import type { SupplierRecord, SupplierRole } from '../types';

export type FormSection = 'basic' | 'address' | 'contact' | 'tax' | 'bank' | 'license' | 'remark';

export function canCreateSupplier(role: SupplierRole): boolean {
  return role === 'businessAdmin';
}

export function canEditSection(role: SupplierRole, section: FormSection): boolean {
  if (role === 'viewer') return false;
  if (role === 'businessAdmin') {
    return (
      section === 'basic'
      || section === 'address'
      || section === 'contact'
      || section === 'remark'
      || section === 'license'
      || section === 'tax'
      || section === 'bank'
    );
  }
  if (role === 'finance') {
    return section === 'tax' || section === 'bank';
  }
  if (role === 'compliance') {
    return section === 'license';
  }
  return false;
}

export function canReviewLicense(role: SupplierRole): boolean {
  return role === 'compliance';
}

export function canDeleteSupplier(record: SupplierRecord): boolean {
  return !record.hasLinkedContract && !record.hasLinkedPayment;
}

export function getDeleteActionLabel(record: SupplierRecord): '删除' | '停用' {
  return canDeleteSupplier(record) ? '删除' : '停用';
}
