import { EntitySchema } from '@mikro-orm/core';
import { v4 as uuidv4 } from 'uuid';
import { BaseEntity } from '../../core/entities/base.entity';

export class Gift extends BaseEntity {
  name!: string;
  description?: string;
  imageUrl?: string;
  price?: number;
  experience?: boolean;
  status: string = 'pending';
  ownerId?: string;
}

export const GiftSchema = new EntitySchema<Gift>({
  class: Gift,
  tableName: 'gifts',
  properties: {
    id: {
      type: 'uuid',
      primary: true,
      default: uuidv4(),
    },
    tenantId: {
      type: 'string',
    },
    metadata: {
      type: 'json',
      nullable: true,
    },
    createdAt: {
      type: 'date',
      default: new Date(),
    },
    updatedAt: {
      type: 'date',
      default: new Date(),
    },
    name: {
      type: 'string',
    },
    description: {
      type: 'string',
      nullable: true,
    },
    imageUrl: {
      type: 'string',
      nullable: true,
    },
    price: {
      type: 'float',
      nullable: true,
    },
    experience: {
      type: 'boolean',
      nullable: true,
    },
    status: {
      type: 'string',
      default: 'pending',
    },
    ownerId: {
      type: 'string',
      nullable: true,
    },
  },
});

export class GiftContribution extends BaseEntity {
  giftId!: string;
  contributorName!: string;
  contributorEmail?: string;
  amount!: number;
  type: string = 'individual';
  status: string = 'pending';
}

export const GiftContributionSchema = new EntitySchema<GiftContribution>({
  class: GiftContribution,
  tableName: 'gift_contributions',
  properties: {
    id: {
      type: 'uuid',
      primary: true,
      default: uuidv4(),
    },
    tenantId: {
      type: 'string',
    },
    metadata: {
      type: 'json',
      nullable: true,
    },
    createdAt: {
      type: 'date',
      default: new Date(),
    },
    updatedAt: {
      type: 'date',
      default: new Date(),
    },
    giftId: {
      type: 'uuid',
    },
    contributorName: {
      type: 'string',
    },
    contributorEmail: {
      type: 'string',
      nullable: true,
    },
    amount: {
      type: 'float',
    },
    type: {
      type: 'string',
      default: 'individual',
    },
    status: {
      type: 'string',
      default: 'pending',
    },
  },
});
