package com.platform.modules.live.aspect;

import com.platform.plugs.common.rpc.ResponseResult;
import com.platform.plugs.common.rpc.RpcResponse;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.lang.reflect.Method;

/**
 * @author TONG
 * 2019/11/14 14:11
 **/
@Aspect
@Component
public class CasterTenantAspect extends BaseTenantAspect {

    public CasterTenantAspect(ApplicationContext applicationContext) {
        super(applicationContext);
    }

    @Around("@annotation(com.platform.modules.live.aspect.CasterTenant)")
    public Object doLiveSceneValid(ProceedingJoinPoint pjp) throws Throwable {
        return super.doTenantValid(pjp);
    }

    @Override
    public TenantAspectRegistry buildTenantAspectRegistry(Method method) {
        CasterTenant casterTenant = method.getAnnotation(CasterTenant.class);
        if (casterTenant == null) {
            return null;
        }
        return new TenantAspectRegistry(casterTenant.value(), casterTenant.tenantTableClazz(), casterTenant.method(), String.class);
    }

    public Object errorResponse(int errorCode, String errorMsg) {
        return new RpcResponse(RpcResponse.ERROR_STATUS, ResponseResult.ERROR, errorCode + "", errorMsg);
    }
}
