//
//  CooperationOrderModelsTests.swift
//  suixinkanTests
//

import XCTest
@testable import suixinkan

/// 合作订单模型与校验测试。
final class CooperationOrderModelsTests: XCTestCase {

    func testRemarkNameValidationAllowsTenCharacters() {
        XCTAssertNil(CooperationOrderFeature.remarkNameValidationMessage("1234567890"))
    }

    func testRemarkNameValidationRejectsOverTenCharacters() {
        XCTAssertEqual(
            CooperationOrderFeature.remarkNameValidationMessage("12345678901"),
            "备注名不能超过10个字符"
        )
    }

    func testReferralLeadDisplayFields() throws {
        let json = """
        {
          "id": 1,
          "lead_id": 9,
          "display_name": "展示名",
          "user_mobile_masked": "138****0000",
          "remark": "备注",
          "created_at": "2026-01-01",
          "image_urls": ["https://img/1.jpg"]
        }
        """.data(using: .utf8)!
        let lead = try JSONDecoder().decode(ReferralLeadEntity.self, from: json)
        XCTAssertEqual(lead.displayId, "9")
        XCTAssertEqual(lead.displayPhone, "138****0000")
        XCTAssertEqual(lead.displaySalerName, "展示名")
        XCTAssertEqual(lead.displayImages, ["https://img/1.jpg"])
    }

    func testAcquisitionOrderDisplayFields() throws {
        let json = """
        {
          "project_name": "跟拍套餐",
          "order_type_label": "摄影师跟拍",
          "order_number": "NO001",
          "photog_remark_name": "备注名",
          "sale_user_name": "获客员",
          "created_at": "2026-01-02",
          "user_mobile_masked": "139****1111",
          "order_amount": "99.00"
        }
        """.data(using: .utf8)!
        let order = try JSONDecoder().decode(AcquisitionOrderEntity.self, from: json)
        XCTAssertEqual(order.displayPartner, "备注名")
        XCTAssertEqual(order.displayCustomerPhone, "139****1111")
        XCTAssertEqual(order.displayAmount, "99.00")
    }

    func testCooperativeSalerDisplayCommissionRateUsesLabelFirst() {
        let entity = CooperativeSalerEntity(
            commissionRate: 10,
            commissionRateLabel: "10%（固定）"
        )
        XCTAssertEqual(entity.displayCommissionRate, "10%（固定）")
    }
}
