import { DateTime } from 'luxon'
import { ManyToMany, column, manyToMany } from '@ioc:Adonis/Lucid/Orm'
import { stringArrayConverter, jsonConverter, decimalConverter } from 'App/Helpers/db'
import Decimal from 'decimal.js'
import AppBaseModel from './AppBaseModel'
import Category from './Category'
export default class Series extends AppBaseModel {
    @column({ isPrimary: true })
    public id: number

    @column.dateTime({ autoCreate: true })
    public createdAt: DateTime

    @column.dateTime({ autoCreate: true, autoUpdate: true })
    public updatedAt: DateTime

    @column()
    public title: string

    @column()
    public description?: string

    @column()
    public cover?: string

    @column()
    public landscapeCover?: string

    @column({ ...stringArrayConverter })
    public tags?: string[]

    @manyToMany(() => Category, {
        pivotTable: 'category_series',
        localKey: 'id',
        pivotForeignKey: 'series_id',
        relatedKey: 'id',
        pivotRelatedForeignKey: 'category_id'
    })
    public categories: ManyToMany<typeof Category>

    @column.dateTime()
    public releaseDate?: DateTime

    @column({ ...jsonConverter })
    public meta?: any

    @column()
    public playCount: number

    @column({ ...decimalConverter })
    public price: Decimal

    @column()
    public totalEpisodes: number
}
