package com.red.circle.other.app.service.violation;

import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.app.command.violation.query.ViolationRecordPageQryExe;
import com.red.circle.other.app.command.violation.user.UserViolationAdjustCmdExe;
import com.red.circle.other.app.command.violation.user.UserViolationWarningCmdExe;
import com.red.circle.other.app.dto.cmd.violation.UserViolationHandleCmd;
import com.red.circle.other.app.dto.cmd.violation.ViolationRecordPageQueryCmd;
import com.red.circle.other.app.dto.clientobject.violation.ViolationHandleResultCO;
import com.red.circle.other.app.dto.clientobject.violation.ViolationRecordCO;
import com.red.circle.other.app.enums.violation.OperationTypeEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * 用户违规服务实现
 */
@Service
@RequiredArgsConstructor
public class UserViolationServiceImpl implements UserViolationService {

    private final UserViolationWarningCmdExe userViolationWarningCmdExe;
    private final UserViolationAdjustCmdExe userViolationAdjustCmdExe;
    private final ViolationRecordPageQryExe violationRecordPageQryExe;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ViolationHandleResultCO handle(UserViolationHandleCmd cmd) {
        if (Objects.equals(cmd.getOperationType(), OperationTypeEnum.WARNING.getCode())) {
            return userViolationWarningCmdExe.execute(cmd);
        } else {
            return userViolationAdjustCmdExe.execute(cmd);
        }
    }

    @Override
    public PageResult<ViolationRecordCO> pageQuery(ViolationRecordPageQueryCmd cmd) {
        return violationRecordPageQryExe.execute(cmd);
    }
}
