import {
  ClientAgreementProps,
  AttachmentProps,
} from '@/utils/types/legal-agreements.types';

export interface Contract {
  id: number;
  name: string;
  content?: string;
  description?: string;
  type?: string;
  attachment?: {
    url: string;
  };
}

export function buildAttachment(contract: {
  attachment?: { url: string };
  name: string;
}): AttachmentProps {
  return {
    id: 0,
    url: contract.attachment?.url || '',
    downloadUrl: contract.attachment?.url || '',
    caption: contract.name,
    type: 'contract',
    extension: 'pdf',
    size: 0,
    created_at: '',
    updated_at: '',
  };
}

export function buildAgreementFromContract(
  contract: Contract
): ClientAgreementProps {
  return {
    id: contract.id,
    name: contract.name,
    type: contract.type || 'contract',
    attachment: buildAttachment(contract),
    client: {} as any,
    author: {} as any,
    contract: {
      id: contract.id,
      name: contract.name,
      description: contract.description || '',
      type: contract.type || 'contract',
      content: contract.content || '',
      created_at: '',
      updated_at: '',
      workflows_count: null,
    },
    agreement_signed: '',
    created_at: '',
    updated_at: '',
  };
}
