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'
import Series from 'App/Models/Series'
import Episode from 'App/Models/Episode'

export enum BalanceRecordType {
    Recharge = 'recharge',
    Purchase = 'purchase',
    Signin = 'signin',
    Reward = 'reward'
}

export default class BalanceRecord 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 amount: Decimal

    @column()
    public type: BalanceRecordType

    @column()
    public description?: string

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

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

    @column()
    public seriesId?: number

    @column()
    public episodeId?: number

    @computed()
    public series?: Series

    @computed()
    public episode?: Episode
}
