-import * as Sequelize from 'sequelize'
-import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers'
-import { isVideoChannelUrlValid } from '../../helpers/custom-validators/video-channels'
-import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
-import { sendDeleteVideoChannel } from '../../lib/activitypub/send/send-delete'
-
-import { addMethodsToModel, getSort } from '../utils'
-import { VideoChannelAttributes, VideoChannelInstance, VideoChannelMethods } from './video-channel-interface'
-import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url'
-import { activityPubCollection } from '../../helpers/activitypub'
-
-let VideoChannel: Sequelize.Model<VideoChannelInstance, VideoChannelAttributes>
-let toFormattedJSON: VideoChannelMethods.ToFormattedJSON
-let toActivityPubObject: VideoChannelMethods.ToActivityPubObject
-let isOwned: VideoChannelMethods.IsOwned
-let countByAccount: VideoChannelMethods.CountByAccount
-let listForApi: VideoChannelMethods.ListForApi
-let listByAccount: VideoChannelMethods.ListByAccount
-let loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount
-let loadByUUID: VideoChannelMethods.LoadByUUID
-let loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount
-let loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount
-let loadByHostAndUUID: VideoChannelMethods.LoadByHostAndUUID
-let loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos
-let loadByUrl: VideoChannelMethods.LoadByUrl
-let loadByUUIDOrUrl: VideoChannelMethods.LoadByUUIDOrUrl
-
-export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
- VideoChannel = sequelize.define<VideoChannelInstance, VideoChannelAttributes>('VideoChannel',
+import { FindOptions, Includeable, literal, Op, QueryTypes, ScopeOptions, Transaction, WhereOptions } from 'sequelize'
+import {
+ AllowNull,
+ BeforeDestroy,
+ BelongsTo,
+ Column,
+ CreatedAt,
+ DataType,
+ Default,
+ DefaultScope,
+ ForeignKey,
+ HasMany,
+ Is,
+ Model,
+ Scopes,
+ Sequelize,
+ Table,
+ UpdatedAt
+} from 'sequelize-typescript'
+import { CONFIG } from '@server/initializers/config'
+import { MAccountActor } from '@server/types/models'
+import { pick } from '@shared/core-utils'
+import { AttributesOnly } from '@shared/typescript-utils'
+import { ActivityPubActor } from '../../../shared/models/activitypub'
+import { VideoChannel, VideoChannelSummary } from '../../../shared/models/videos'
+import {
+ isVideoChannelDescriptionValid,
+ isVideoChannelDisplayNameValid,
+ isVideoChannelSupportValid
+} from '../../helpers/custom-validators/video-channels'
+import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
+import { sendDeleteActor } from '../../lib/activitypub/send'
+import {
+ MChannel,
+ MChannelActor,
+ MChannelAP,
+ MChannelBannerAccountDefault,
+ MChannelFormattable,
+ MChannelSummaryFormattable
+} from '../../types/models/video'
+import { AccountModel, ScopeNames as AccountModelScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account'
+import { ActorModel, unusedActorAttributesForAPI } from '../actor/actor'
+import { ActorFollowModel } from '../actor/actor-follow'
+import { ActorImageModel } from '../actor/actor-image'
+import { ServerModel } from '../server/server'
+import { setAsUpdated } from '../shared'
+import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils'
+import { VideoModel } from './video'
+import { VideoPlaylistModel } from './video-playlist'
+
+export enum ScopeNames {
+ FOR_API = 'FOR_API',
+ SUMMARY = 'SUMMARY',
+ WITH_ACCOUNT = 'WITH_ACCOUNT',
+ WITH_ACTOR = 'WITH_ACTOR',
+ WITH_ACTOR_BANNER = 'WITH_ACTOR_BANNER',
+ WITH_VIDEOS = 'WITH_VIDEOS',
+ WITH_STATS = 'WITH_STATS'
+}
+
+type AvailableForListOptions = {
+ actorId: number
+ search?: string
+ host?: string
+ handles?: string[]
+ forCount?: boolean
+}
+
+type AvailableWithStatsOptions = {
+ daysPrior: number
+}
+
+export type SummaryOptions = {
+ actorRequired?: boolean // Default: true
+ withAccount?: boolean // Default: false
+ withAccountBlockerIds?: number[]
+}
+
+@DefaultScope(() => ({
+ include: [