import { describe, it, expect } from 'vitest'
import {
  countrySchema,
  topologyNodeSchema,
  topologyEdgeSchema,
  networkTopologySchema,
  complianceRequirementSchema,
  deploymentMilestoneSchema,
  costEstimateSchema,
} from '../schemas/infrastructure'

describe('Infrastructure Validation Schemas', () => {
  describe('countrySchema', () => {
    it('should validate a valid country', () => {
      const validCountry = {
        name: 'Italy',
        region: 'Europe',
        relationshipType: 'Full Diplomatic Relations',
        priority: 'High',
        cloudflareCoverage: true,
        networkInfrastructurePriority: 'Critical',
      }

      expect(() => countrySchema.parse(validCountry)).not.toThrow()
    })

    it('should reject invalid region', () => {
      const invalidCountry = {
        name: 'Italy',
        region: 'Invalid Region',
        relationshipType: 'Full Diplomatic Relations',
        priority: 'High',
        cloudflareCoverage: true,
        networkInfrastructurePriority: 'Critical',
      }

      expect(() => countrySchema.parse(invalidCountry)).toThrow()
    })

    it('should reject missing required fields', () => {
      const invalidCountry = {
        name: 'Italy',
        // Missing required fields
      }

      expect(() => countrySchema.parse(invalidCountry)).toThrow()
    })
  })

  describe('topologyNodeSchema', () => {
    it('should validate a valid node', () => {
      const validNode = {
        id: 'node-1',
        type: 'vm',
        label: 'VM 1',
        region: 'Europe',
        entity: 'SMOM',
        position: { x: 100, y: 200 },
        metadata: {},
      }

      expect(() => topologyNodeSchema.parse(validNode)).not.toThrow()
    })

    it('should reject invalid node type', () => {
      const invalidNode = {
        id: 'node-1',
        type: 'invalid-type',
        label: 'Node',
        region: 'Europe',
        entity: 'SMOM',
        position: { x: 0, y: 0 },
        metadata: {},
      }

      expect(() => topologyNodeSchema.parse(invalidNode)).toThrow()
    })
  })

  describe('topologyEdgeSchema', () => {
    it('should validate a valid edge', () => {
      const validEdge = {
        id: 'edge-1',
        source: 'node-1',
        target: 'node-2',
        type: 'network-route',
        metadata: {},
      }

      expect(() => topologyEdgeSchema.parse(validEdge)).not.toThrow()
    })
  })

  describe('networkTopologySchema', () => {
    it('should validate a valid topology', () => {
      const validTopology = {
        id: 'topology-1',
        region: 'Europe',
        entity: 'SMOM',
        nodes: [
          {
            id: 'node-1',
            type: 'vm',
            label: 'VM 1',
            region: 'Europe',
            entity: 'SMOM',
            position: { x: 0, y: 0 },
            metadata: {},
          },
        ],
        edges: [
          {
            id: 'edge-1',
            source: 'node-1',
            target: 'node-2',
            type: 'network-route',
            metadata: {},
          },
        ],
        lastUpdated: new Date().toISOString(),
      }

      expect(() => networkTopologySchema.parse(validTopology)).not.toThrow()
    })
  })

  describe('complianceRequirementSchema', () => {
    it('should validate a valid compliance requirement', () => {
      const validRequirement = {
        country: 'Italy',
        region: 'Europe',
        frameworks: ['GDPR'],
        status: 'Compliant',
        requirements: ['Data protection'],
      }

      expect(() => complianceRequirementSchema.parse(validRequirement)).not.toThrow()
    })

    it('should reject invalid status', () => {
      const invalidRequirement = {
        country: 'Italy',
        region: 'Europe',
        frameworks: ['GDPR'],
        status: 'Invalid Status',
        requirements: [],
      }

      expect(() => complianceRequirementSchema.parse(invalidRequirement)).toThrow()
    })
  })

  describe('deploymentMilestoneSchema', () => {
    it('should validate a valid milestone', () => {
      const validMilestone = {
        id: 'milestone-1',
        title: 'Deploy Infrastructure',
        region: 'Europe',
        entity: 'SMOM',
        priority: 'High',
        startDate: '2024-01-01',
        endDate: '2024-01-31',
        status: 'Planned',
        dependencies: [],
        cost: 10000,
        description: 'Deploy infrastructure',
      }

      expect(() => deploymentMilestoneSchema.parse(validMilestone)).not.toThrow()
    })

    it('should reject invalid priority', () => {
      const invalidMilestone = {
        id: 'milestone-1',
        title: 'Deploy',
        region: 'Europe',
        entity: 'SMOM',
        priority: 'Invalid Priority',
        startDate: '2024-01-01',
        endDate: '2024-01-31',
        status: 'Planned',
        dependencies: [],
      }

      expect(() => deploymentMilestoneSchema.parse(invalidMilestone)).toThrow()
    })
  })

  describe('costEstimateSchema', () => {
    it('should validate a valid cost estimate', () => {
      const validEstimate = {
        region: 'Europe',
        entity: 'SMOM',
        category: 'Infrastructure',
        monthly: 1000,
        annual: 12000,
        breakdown: {
          compute: 500,
          storage: 200,
          network: 300,
        },
        currency: 'USD',
        lastUpdated: new Date().toISOString(),
      }

      expect(() => costEstimateSchema.parse(validEstimate)).not.toThrow()
    })

    it('should reject negative costs', () => {
      const invalidEstimate = {
        region: 'Europe',
        entity: 'SMOM',
        category: 'Infrastructure',
        monthly: -1000,
        annual: -12000,
        breakdown: {},
        currency: 'USD',
      }

      expect(() => costEstimateSchema.parse(invalidEstimate)).toThrow()
    })
  })
})

