import { Column, CreateDateColumn, Entity, PrimaryColumn } from 'typeorm'

export enum MemberType {
    Trial = 'TRIAL',
    Paid = 'PAID'
}

@Entity()
export class Membership {
    @PrimaryColumn()
    userId: number

    @Column()
    expireAt: Date

    @Column({ nullable: true })
    planId?: number

    @CreateDateColumn()
    createdAt: Date

    @Column({ type: 'enum', enum: MemberType, default: MemberType.Trial })
    memberType: MemberType

    @Column()
    tokenLeft: number

    get isExpired() {
        return this.expireAt.getTime() < Date.now()
    }
}
