import { DateTime } from 'luxon'
import { column, computed } from '@ioc:Adonis/Lucid/Orm'
import Decimal from 'decimal.js'
import { decimalConverter } from 'App/Helpers/db'
import AppBaseModel from './AppBaseModel'
export default class Episode extends AppBaseModel {
    // public static namingStrategy = new CamelCaseNamingStrategy()

    @column({ isPrimary: true })
    public id: number

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

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

    @column()
    public seriesId: number

    @column()
    public title: string

    @column()
    public episodeNum: number

    @column()
    public description?: string

    @column()
    public cover?: string

    @column({ serializeAs: null })
    public video?: string

    @column()
    public playCount: number

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

    public purchased: boolean = false

    public signedUrl: string

    @computed()
    public get playUrl() {
        if (this.purchased) {
            return this.signedUrl
        }
        return null
    }
}
