import {
    Column,
    CreateDateColumn,
    Entity,
    JoinColumn,
    ManyToOne,
    PrimaryGeneratedColumn,
} from "typeorm";
import { PaymentEntity } from "./payment.entity";

@Entity({ schema: "freight", name: "payment_refunds" })
export class PaymentRefundEntity {
    @PrimaryGeneratedColumn("uuid")
    id!: string;

    @Column({ type: "uuid", name: "payment_id" })
    paymentId!: string;

    @Column({ type: "int", name: "amount_minor" })
    amountMinor!: number;

    @Column({ type: "varchar", length: 255, nullable: true })
    reason?: string;

    @Column({ type: "varchar", length: 255, nullable: true, name: "provider_refund_id" })
    providerRefundId?: string;

    @Column({ type: "varchar", length: 50 })
    status!: string;

    @CreateDateColumn({ name: "created_at" })
    createdAt!: Date;

    @ManyToOne(() => PaymentEntity, (payment) => payment.refunds, { onDelete: "RESTRICT" })
    @JoinColumn({ name: "payment_id" })
    payment!: PaymentEntity;
}
