import { describe, it, expect } from 'vitest';
import { testClient } from 'hono/testing';

// 导入史诗012新增的企业路由
import { enterpriseAuthApiRoutes, enterpriseCompanyApiRoutes, enterpriseDisabilityApiRoutes, orderApiRoutes } from '../../src/index';

describe('史诗012新增路由连通性集成测试', () => {
  describe('企业用户认证路由连通性测试', () => {
    it('应该能够访问企业用户登录端点 (POST /api/v1/yongren/auth/login)', async () => {
      const client = testClient(enterpriseAuthApiRoutes);
      const response = await client.api.v1.yongren.auth.login.$post({
        json: { phone: '13800138000', password: 'testpassword' }
      });

      // 只测试路由连通性，不测试具体业务逻辑
      // 可能返回401（需要认证）、200（成功）或400（请求无效）
      expect([200, 401, 400]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问企业用户登出端点 (POST /api/v1/yongren/auth/logout)', async () => {
      const client = testClient(enterpriseAuthApiRoutes);
      const response = await client.api.v1.yongren.auth.logout.$post({
        json: {}
      });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问企业用户信息端点 (GET /api/v1/yongren/auth/me)', async () => {
      const client = testClient(enterpriseAuthApiRoutes);
      const response = await client.api.v1.yongren.auth.me.$get();

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });
  });

  describe('企业统计路由连通性测试', () => {
    it('应该能够访问企业统计概览端点 (GET /api/v1/yongren/company/overview)', async () => {
      const client = testClient(enterpriseCompanyApiRoutes);
      const response = await client.api.v1.yongren.company.overview.$get();

      // 只测试路由连通性，不测试具体业务逻辑
      // 可能返回401（需要认证）或200（如果端点不需要认证）
      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问企业人才统计端点 (GET /api/v1/yongren/company/{id}/talents)', async () => {
      const client = testClient(enterpriseCompanyApiRoutes);
      const response = await client.api.v1.yongren.company[':id'].talents.$get({
        param: { id: '1' }
      });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });
  });

  describe('残疾人扩展路由连通性测试', () => {
    it('应该能够访问残疾人工作历史端点 (GET /api/v1/yongren/disability-person/{id}/work-history)', async () => {
      const client = testClient(enterpriseDisabilityApiRoutes);
      const response = await client.api.v1.yongren['disability-person'][':id']['work-history'].$get({
        param: { id: '1' }
      });

      // 只测试路由连通性，不测试具体业务逻辑
      // 可能返回401（需要认证）或200（如果端点不需要认证）
      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问残疾人薪资历史端点 (GET /api/v1/yongren/disability-person/{id}/salary-history)', async () => {
      const client = testClient(enterpriseDisabilityApiRoutes);
      const response = await client.api.v1.yongren['disability-person'][':id']['salary-history'].$get({
        param: { id: '1' }
      });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问残疾人征信信息端点 (GET /api/v1/yongren/disability-person/{id}/credit-info)', async () => {
      const client = testClient(enterpriseDisabilityApiRoutes);
      const response = await client.api.v1.yongren['disability-person'][':id']['credit-info'].$get({
        param: { id: '1' }
      });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问残疾人视频关联端点 (GET /api/v1/yongren/disability-person/{id}/videos)', async () => {
      const client = testClient(enterpriseDisabilityApiRoutes);
      const response = await client.api.v1.yongren['disability-person'][':id'].videos.$get({
        param: { id: '1' }
      });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });
  });

  describe('订单模块企业功能路由连通性测试', () => {
    it('应该能够访问打卡统计端点 (GET /api/v1/order/checkin-statistics)', async () => {
      const client = testClient(orderApiRoutes);
      const response = await client.api.v1.order['checkin-statistics'].$get({ query: {} });

      // 只测试路由连通性，不测试具体业务逻辑
      // 可能返回401（需要认证）或200（如果端点不需要认证）
      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问视频统计端点 (GET /api/v1/order/video-statistics)', async () => {
      const client = testClient(orderApiRoutes);
      const response = await client.api.v1.order['video-statistics'].$get({ query: {} });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问企业订单端点 (GET /api/v1/order/company-orders)', async () => {
      const client = testClient(orderApiRoutes);
      const response = await client.api.v1.order['company-orders'].$get({ query: {} });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问企业视频端点 (GET /api/v1/order/company-videos)', async () => {
      const client = testClient(orderApiRoutes);
      const response = await client.api.v1.order['company-videos'].$get({ query: {} });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问批量下载端点 (POST /api/v1/order/batch-download)', async () => {
      const client = testClient(orderApiRoutes);
      const response = await client.api.v1.order['batch-download'].$post({
        json: { downloadScope: 'company' as any }
      });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });

    it('应该能够访问视频状态更新端点 (PUT /api/v1/order/videos/{id}/status)', async () => {
      const client = testClient(orderApiRoutes);
      const response = await client.api.v1.order.videos[':id'].status.$put({
        param: { id: '1' },
        json: { status: 'completed' as any }
      });

      expect([200, 401]).toContain(response.status);

      if (response.status === 200) {
        const responseData = await response.json();
        expect(responseData).toHaveProperty('success');
        expect(responseData).toHaveProperty('data');
        expect(responseData).toHaveProperty('message');
      }
    });
  });
});