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

// 导入Allin模块路由
import { channelApiRoutes } from '../../src/index';
import { companyApiRoutes } from '../../src/index';
import { disabilityApiRoutes } from '../../src/index';
import { orderApiRoutes } from '../../src/index';
import { platformApiRoutes } from '../../src/index';
import { salaryApiRoutes } from '../../src/index';

describe('Allin模块API路由连通性集成测试', () => {
  describe('渠道管理模块路由连通性测试', () => {
    it('应该能够访问渠道列表端点 (GET /api/v1/channel/getAllChannels)', async () => {
      const client = testClient(channelApiRoutes);
      const response = await client.api.v1.channel.getAllChannels.$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');
      }
    });
  });

  describe('公司管理模块路由连通性测试', () => {
    it('应该能够访问公司列表端点 (GET /api/v1/company/getAllCompanies)', async () => {
      const client = testClient(companyApiRoutes);
      const response = await client.api.v1.company.getAllCompanies.$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');
      }
    });
  });

  describe('残疾人管理模块路由连通性测试', () => {
    it('应该能够访问残疾人列表端点 (GET /api/v1/disability/getAllDisabledPersons)', async () => {
      const client = testClient(disabilityApiRoutes);
      const response = await client.api.v1.disability.getAllDisabledPersons.$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');
      }
    });
  });

  describe('订单管理模块路由连通性测试', () => {
    it('应该能够访问订单列表端点 (GET /api/v1/order/list)', async () => {
      const client = testClient(orderApiRoutes);
      const response = await client.api.v1.order.list.$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');
      }
    });
  });

  describe('平台管理模块路由连通性测试', () => {
    it('应该能够访问平台列表端点 (GET /api/v1/platform/getAllPlatforms)', async () => {
      const client = testClient(platformApiRoutes);
      const response = await client.api.v1.platform.getAllPlatforms.$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');
      }
    });
  });

  describe('薪资管理模块路由连通性测试', () => {
    it('应该能够访问薪资列表端点 (GET /api/v1/salary/list)', async () => {
      const client = testClient(salaryApiRoutes);
      const response = await client.api.v1.salary.list.$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');
      }
    });
  });
});