package com.ruoyi.generator.service.front;

import com.ruoyi.generator.domain.GenProject;
import com.ruoyi.generator.domain.front.FrontProject;
import com.ruoyi.generator.domain.front.FrontProjectColumn;
import com.ruoyi.generator.domain.front.FrontProjectTable;
import org.junit.Test;

import java.util.Collections;

import static org.junit.Assert.assertEquals;

public class FrontProjectConverterTest
{
    @Test
    public void convertsFrontDraftToGenProject()
    {
        FrontProject project = new FrontProject();
        project.setProjectId(10L);
        project.setProjectName("车辆管理系统");
        project.setProjectFileName("vehicle-system");
        project.setPackageName("com.easycode.vehicle");
        project.setVersion("1.0.0");
        project.setFrontFramework("Vue3 + Element Plus");
        project.setBackFramework("Spring Boot + MyBatis");

        FrontProjectTable table = new FrontProjectTable();
        table.setTableId(20L);
        table.setTableName("car_info");
        table.setTableComment("车辆信息表");
        table.setClassName("CarInfo");
        table.setModuleName("vehicle");
        table.setBusinessName("car");
        table.setFunctionName("车辆信息");

        FrontProjectColumn column = new FrontProjectColumn();
        column.setColumnId(30L);
        column.setColumnName("car_id");
        column.setColumnComment("车辆ID");
        column.setColumnType("bigint(20)");
        column.setJavaType("Long");
        column.setJavaField("carId");
        column.setIsPk("1");
        column.setIsIncrement("1");
        table.setColumns(Collections.singletonList(column));
        project.setTables(Collections.singletonList(table));

        GenProject genProject = FrontProjectConverter.toGenProject(project);

        assertEquals("车辆管理系统", genProject.getProjectName());
        assertEquals("com.easycode.vehicle", genProject.getPackageName());
        assertEquals(1, genProject.getTables().size());
        assertEquals("car_info", genProject.getTables().get(0).getTableName());
        assertEquals("carId", genProject.getTables().get(0).getColumns().get(0).getJavaField());
    }
}
