import type { z } from 'zod'
import {
  BaseCompanySchema,
  BaseContactSchema,
  BaseDealSchema,
  BaseMilestoneSchema,
  BaseProjectSchema,
  BaseTaskSchema
} from '../business/base-entities'

type BaseProjectFixture = z.infer<typeof BaseProjectSchema>
type BaseDealFixture = z.infer<typeof BaseDealSchema>
type BaseCompanyFixture = z.infer<typeof BaseCompanySchema>
type BaseContactFixture = z.infer<typeof BaseContactSchema>
type BaseMilestoneFixture = z.infer<typeof BaseMilestoneSchema>
type BaseTaskFixture = z.infer<typeof BaseTaskSchema>

const DEFAULT_ORGANIZATION_ID = '00000000-0000-0000-0000-000000000010'
const DEFAULT_PROJECT_ID = '00000000-0000-0000-0000-000000000100'
const DEFAULT_TIMESTAMP = '2025-01-01T00:00:00Z'

export function makeProject(overrides: Partial<BaseProjectFixture> = {}): BaseProjectFixture {
  return BaseProjectSchema.parse({
    id: DEFAULT_PROJECT_ID,
    organizationId: DEFAULT_ORGANIZATION_ID,
    name: 'Test Project',
    kind: 'client-delivery',
    status: 'active',
    description: 'A test project',
    metadata: {},
    createdAt: DEFAULT_TIMESTAMP,
    updatedAt: DEFAULT_TIMESTAMP,
    ...overrides
  })
}

export function makeDeal(overrides: Partial<BaseDealFixture> = {}): BaseDealFixture {
  return BaseDealSchema.parse({
    id: '00000000-0000-0000-0000-000000000200',
    organizationId: DEFAULT_ORGANIZATION_ID,
    contactEmail: 'buyer@test.com',
    stage: 'qualified',
    metadata: {},
    createdAt: DEFAULT_TIMESTAMP,
    updatedAt: DEFAULT_TIMESTAMP,
    ...overrides
  })
}

export function makeCompany(overrides: Partial<BaseCompanyFixture> = {}): BaseCompanyFixture {
  return BaseCompanySchema.parse({
    id: '00000000-0000-0000-0000-000000000300',
    organizationId: DEFAULT_ORGANIZATION_ID,
    name: 'Test Company',
    domain: 'test.example',
    status: 'active',
    metadata: {},
    createdAt: DEFAULT_TIMESTAMP,
    updatedAt: DEFAULT_TIMESTAMP,
    ...overrides
  })
}

export function makeContact(overrides: Partial<BaseContactFixture> = {}): BaseContactFixture {
  return BaseContactSchema.parse({
    id: '00000000-0000-0000-0000-000000000400',
    organizationId: DEFAULT_ORGANIZATION_ID,
    email: 'contact@test.com',
    firstName: 'Test',
    lastName: 'Contact',
    status: 'active',
    metadata: {},
    createdAt: DEFAULT_TIMESTAMP,
    updatedAt: DEFAULT_TIMESTAMP,
    ...overrides
  })
}

export function makeMilestone(overrides: Partial<BaseMilestoneFixture> = {}): BaseMilestoneFixture {
  return BaseMilestoneSchema.parse({
    id: '00000000-0000-0000-0000-000000000500',
    organizationId: DEFAULT_ORGANIZATION_ID,
    projectId: DEFAULT_PROJECT_ID,
    name: 'Test Milestone',
    status: 'not-started',
    description: 'A test milestone',
    metadata: {},
    createdAt: DEFAULT_TIMESTAMP,
    updatedAt: DEFAULT_TIMESTAMP,
    ...overrides
  })
}

export function makeTask(overrides: Partial<BaseTaskFixture> = {}): BaseTaskFixture {
  return BaseTaskSchema.parse({
    id: '00000000-0000-0000-0000-000000000600',
    organizationId: DEFAULT_ORGANIZATION_ID,
    projectId: DEFAULT_PROJECT_ID,
    name: 'Test Task',
    status: 'todo',
    type: 'general',
    description: 'A test task',
    metadata: {},
    createdAt: DEFAULT_TIMESTAMP,
    updatedAt: DEFAULT_TIMESTAMP,
    ...overrides
  })
}
