# Code generated by Lark OpenAPI.

import lark_oapi as lark
from lark_oapi.api.corehr.v2 import *


def main():
    # 创建client
    client = lark.Client.builder() \
        .app_id(lark.APP_ID) \
        .app_secret(lark.APP_SECRET) \
        .log_level(lark.LogLevel.DEBUG) \
        .build()

    # 构造请求对象
    request: PatchEmployeesInternationalAssignmentRequest = PatchEmployeesInternationalAssignmentRequest.builder() \
        .international_assignment_id("7127921432117937708") \
        .client_token("12454646") \
        .user_id_type("open_id") \
        .department_id_type("open_department_id") \
        .request_body(EmployeesInternationalAssignmentReq.builder()
                      .work_location_id("7127921432117937708")
                      .service_company("7127921432117937708")
                      .work_shift("work_shift")
                      .weekly_working_hours_v2(8)
                      .working_hours_type_id("7127921432117937708")
                      .employee_type_id("7127921432117937708")
                      .department_id("7127921432117937708")
                      .job_id("7127921432117937708")
                      .job_family_id("7127921432117937708")
                      .job_level_id("7127921432117937708")
                      .job_grade_id("7127921432117937708")
                      .compensation_type("daily")
                      .direct_manager_id("7127921432117937708")
                      .dotted_line_manager_id("7127921432117937708")
                      .work_calendar_id("7127921432117937708")
                      .position_id("7127921432117937708")
                      .custom_fields([])
                      .international_assignment_reason("xxx 项目派遣")
                      .description("xxx 项目")
                      .international_assignment_expected_end_date("2024-01-02")
                      .international_assignment_type("global_assignment")
                      .effective_time("2024-01-02")
                      .expiration_time("2024-01-02")
                      .build()) \
        .build()

    # 发起请求
    response: PatchEmployeesInternationalAssignmentResponse = client.corehr.v2.employees_international_assignment.patch(
        request)

    # 处理失败返回
    if not response.success():
        lark.logger.error(
            f"client.corehr.v2.employees_international_assignment.patch failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}")
        return

    # 处理业务结果
    lark.logger.info(lark.JSON.marshal(response.data, indent=4))


# 异步方式
async def amain():
    # 创建client
    client = lark.Client.builder() \
        .app_id(lark.APP_ID) \
        .app_secret(lark.APP_SECRET) \
        .log_level(lark.LogLevel.DEBUG) \
        .build()

    # 构造请求对象
    request: PatchEmployeesInternationalAssignmentRequest = PatchEmployeesInternationalAssignmentRequest.builder() \
        .international_assignment_id("7127921432117937708") \
        .client_token("12454646") \
        .user_id_type("open_id") \
        .department_id_type("open_department_id") \
        .request_body(EmployeesInternationalAssignmentReq.builder()
                      .work_location_id("7127921432117937708")
                      .service_company("7127921432117937708")
                      .work_shift("work_shift")
                      .weekly_working_hours_v2(8)
                      .working_hours_type_id("7127921432117937708")
                      .employee_type_id("7127921432117937708")
                      .department_id("7127921432117937708")
                      .job_id("7127921432117937708")
                      .job_family_id("7127921432117937708")
                      .job_level_id("7127921432117937708")
                      .job_grade_id("7127921432117937708")
                      .compensation_type("daily")
                      .direct_manager_id("7127921432117937708")
                      .dotted_line_manager_id("7127921432117937708")
                      .work_calendar_id("7127921432117937708")
                      .position_id("7127921432117937708")
                      .custom_fields([])
                      .international_assignment_reason("xxx 项目派遣")
                      .description("xxx 项目")
                      .international_assignment_expected_end_date("2024-01-02")
                      .international_assignment_type("global_assignment")
                      .effective_time("2024-01-02")
                      .expiration_time("2024-01-02")
                      .build()) \
        .build()

    # 发起请求
    response: PatchEmployeesInternationalAssignmentResponse = await client.corehr.v2.employees_international_assignment.apatch(
        request)

    # 处理失败返回
    if not response.success():
        lark.logger.error(
            f"client.corehr.v2.employees_international_assignment.apatch failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}")
        return

    # 处理业务结果
    lark.logger.info(lark.JSON.marshal(response.data, indent=4))


if __name__ == "__main__":
    # asyncio.run(amain()) 异步方式
    main()
