import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';

@Entity({ name: 'billing_payment_methods', schema: 'public' })
export class PaymentMethod {
  @PrimaryGeneratedColumn('uuid')
  id!: string;

  @Column({ name: 'tenant_id', type: 'uuid' })
  tenantId!: string;

  @Column({ type: 'varchar', length: 20 })
  provider!: string; // 'stripe' | 'alipay' | 'wechat_pay' | 'crypto'

  @Column({ name: 'display_name', type: 'varchar', length: 200, default: '' })
  displayName!: string; // e.g. 'Visa *4242', 'Alipay xxx@qq.com'

  @Column({ name: 'is_default', type: 'boolean', default: false })
  isDefault!: boolean;

  @Column({ type: 'jsonb', nullable: true })
  details?: Record<string, any>; // { last4: '4242', brand: 'visa' } — NEVER store full card numbers

  @Column({ name: 'provider_customer_id', type: 'varchar', length: 255, nullable: true })
  providerCustomerId?: string;

  @Column({ name: 'expires_at', type: 'timestamptz', nullable: true })
  expiresAt?: Date;

  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt!: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
  updatedAt!: Date;
}
