module Lark
  module Apis
    module Approval
      #  查看审批定义
      def get(approval_code:, locale: 'zh-CN')
        post 'approval/openapi/v2/approval/get', { approval_code: approval_code, locale: locale }
      end

      # 批量获取审批实例ID
      def list(approval_code:, start_time:, end_time:,offset:,limit:)
        post 'approval/openapi/v2/instance/list',{
          approval_code: approval_code,
          start_time: start_time,
          end_time: end_time,
          offset: offset,
          limit: limit > 100 ? 100 : limit
        }.compact
      end

      # 获取单个审批实例详情
      def get_details(instance_code:, locale: 'zh-CN')
        post 'approval/openapi/v2/instance/get', { instance_code: instance_code, locale: locale }
      end

    #  创建审批实例
      def create_approved(payload={})
        post 'approval/openapi/v2/instance/create',payload
      end

    #  审批任务同意
      def approve(approval_code:, instance_code:, user_id: ,task_id: , comment: nil )
        post 'approval/openapi/v2/instance/approve',{
          approval_code: approval_code,
          instance_code: instance_code,
          user_id: user_id,
          task_id: task_id,
          comment: comment,
        }.compact
      end

    #  审批任务拒绝
      def reject(approval_code:, instance_code:, user_id: ,task_id: , comment: nil )
        post 'approval/openapi/v2/instance/reject',{
          approval_code: approval_code,
          instance_code: instance_code,
          user_id: user_id,
          task_id: task_id,
          comment: comment,
        }.compact
      end

    #  审批任务转交
      def transfer(approval_code:, instance_code:, user_id: ,task_id:, transfer_user_id:, comment: nil )
        post 'approval/openapi/v2/instance/transfer',{
          approval_code: approval_code,
          instance_code: instance_code,
          user_id: user_id,
          task_id: task_id,
          comment: comment,
          transfer_user_id: transfer_user_id,
        }.compact
      end

    #  审批任务撤回
      def cancel(approval_code:, instance_code:, user_id:)
        post 'approval/openapi/v2/instance/cancel',{
          approval_code:approval_code,
          instance_code:instance_code,
          user_id:user_id,
        }.compact
      end
    end
  end
end