package com.kexue.skills.common.util;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;

import java.lang.reflect.Field;

public class FrontUtils {
    public static void main(String[] args) {
//        printList(PurchaseDetail.class);
//        printEditForm(PurchaseDetail.class);
//        printEditMethod(PurchaseDetail.class);
//        printInsertMethod(PurchaseDetail.class);
//        printFormInitValue(PurchaseDetail.class);

//        printList(SaleDetail.class);
//        printEditForm(SaleDetail.class);
//        printEditMethod(SaleDetail.class);
//        printInsertMethod(SaleDetail.class);
//        printFormInitValue(SaleDetail.class);

//        printList(DailySummaryDto.class);
//        printEditForm(DailySummaryDto.class);
//        printEditMethod(DailySummaryDto.class);
//        printInsertMethod(DailySummaryDto.class);
//        printFormInitValue(DailySummaryDto.class);

//        printList(SysUser.class);
//        printEditForm(SysUser.class);
//        printEditMethod(SysUser.class);
//        printInsertMethod(SysUser.class);
//        printFormInitValue(SysUser.class);

//        printList(TradeHistory.class);
//        printEditForm(TradeHistory.class);
//        printEditMethod(TradeHistory.class);
//        printInsertMethod(TradeHistory.class);
//        printFormInitValue(TradeHistory.class);

//        printList(TradeFactory.class);
//        printEditForm(TradeFactory.class);
//        printEditMethod(TradeFactory.class);
//        printInsertMethod(TradeFactory.class);
//        printFormInitValue(TradeFactory.class);

//        printList(AccountTransaction.class);
//        printEditForm(AccountTransaction.class);
//        printEditMethod(AccountTransaction.class);
//        printInsertMethod(AccountTransaction.class);
//        printFormInitValue(AccountTransaction.class);

//        printList(Trade.class);
//        printEditForm(Trade.class);
//        printEditMethod(Trade.class);
//        printInsertMethod(Trade.class);
//        printFormInitValue(Trade.class);

//        printList(Supplier.class);
//        printEditForm(Supplier.class);
//        printEditMethod(Supplier.class);
//        printInsertMethod(Supplier.class);
//        printFormInitValue(Supplier.class);

//        printList(ExpenseAccount.class);
//        printEditForm(ExpenseAccount.class);
//        printEditMethod(ExpenseAccount.class);
//        printInsertMethod(ExpenseAccount.class);
//        printFormInitValue(ExpenseAccount.class);

//        printList(DailyExpenses.class);
//        printEditForm(DailyExpenses.class);
//        printEditMethod(DailyExpenses.class);
//        printInsertMethod(DailyExpenses.class);
//        printFormInitValue(DailyExpenses.class);


//        printList(BizCardProduct.class);
//        printEditForm(BizCardProduct.class);
//        printEditMethod(BizCardProduct.class);
//        printInsertMethod(BizCardProduct.class);
//        printFormInitValue(BizCardProduct.class);

    }

    public static void printList(Class clazz){
        System.out.println("-----------------------printList start-------------------------------------------");
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            if (!declaredField.getName().equals("serialVersionUID")
                    && !declaredField.getName().equals("deleteFlag")
            ){
                ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
                String label = annotation.value();
                if (declaredField.getName().endsWith("Id") || declaredField.getName().equals("id")){
                    String formHtml = "<el-input v-model=\"editForm."+ declaredField.getName() +"\" v-show=\"false\"></el-input>";
                    System.out.println(formHtml);
                }else {
                    String formHtml = "<el-table-column sortable prop=\""+ declaredField.getName() +"\" label=\""+ label +"\" width=\"200\"></el-table-column>";
                    System.out.println(formHtml);
                }
            }
        }
    }
    public static void printEditForm(Class clazz){
        System.out.println("-----------------------printEditForm start-------------------------------------------");
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            if (!declaredField.getName().equals("serialVersionUID")
                    && !declaredField.getName().equals("deleteFlag")
            ){
                ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
                String label = annotation.value();
                if (declaredField.getName().endsWith("Id") || declaredField.getName().equals("id")){
                    String formHtml = "<el-input v-model=\"editForm."+ declaredField.getName() +"\" v-show=\"false\"></el-input>";
                    System.out.println(formHtml);
                }else {
                    String formHtml = "        <el-form-item label=\""+label+"\" prop=\""+declaredField.getName()+"\">\n" +
                            "          <el-input size=\"small\" v-model=\"editForm."+ declaredField.getName() +"\" auto-complete=\"off\" placeholder=\"请输入"+label+"\"></el-input>\n" +
                            "        </el-form-item>";
                    System.out.println(formHtml);
                }
            }
        }
    }

    public static void printEditMethod(Class clazz){
        System.out.println("-----------------------printEditMethod start-------------------------------------------");
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            if (!declaredField.getName().equals("serialVersionUID") && !declaredField.getName().equals("deleteFlag")){
                ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
                String label = annotation.value();
                String formHtml = "             this.editForm."+ declaredField.getName() +" = row."+ declaredField.getName() +"";
                System.out.println(formHtml);
            }
        }
    }

    public static void printInsertMethod(Class clazz){
        System.out.println("-----------------------printInsertMethod start-------------------------------------------");
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            if (!declaredField.getName().equals("serialVersionUID") && !declaredField.getName().equals("deleteFlag")){
                ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
                String label = annotation.value();
                String formHtml = "             this.editForm."+ declaredField.getName() +" = ''";
                System.out.println(formHtml);
            }
        }
    }

    public static void printFormInitValue(Class clazz){
        System.out.println("-----------------------printFormInitValue start-------------------------------------------");
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            if (!declaredField.getName().equals("serialVersionUID") && !declaredField.getName().equals("deleteFlag")){
                ApiModelProperty annotation = declaredField.getAnnotation(ApiModelProperty.class);
                String label = annotation.value();
                String formHtml = ""+ declaredField.getName() +": '',";
                System.out.println(formHtml);
            }
        }
    }
}

