import { DateTime } from 'luxon'
import { column, computed } from '@ioc:Adonis/Lucid/Orm'
import { decimalConverter } from 'App/Helpers/db'
import Decimal from 'decimal.js'
import AppBaseModel from './AppBaseModel'
import Series from 'App/Models/Series'
import Episode from 'App/Models/Episode'

export enum OrderType {
    Series = 'series',
    Episode = 'episode'
}

export default class Order 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 userId: number

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

    @column()
    public type: OrderType

    @column()
    public seriesId: number

    @column()
    public episodeId: number

    @computed()
    public series?: Series

    @computed()
    public episode?: Episode
}
