import { snakeCase } from "change-case";
import { isFileType } from "./TransformText";


export function getSinglePrimaryKey(col: any) {
    let singlePrimaryKeyCol = null;
    for (let i = 0; i < col.length; i++) {
        if (col[i].isPrimary) {
            singlePrimaryKeyCol = snakeCase(col[i].name);
            break;
        }
    }
    return singlePrimaryKeyCol ?? 'id';
}

export function getSinglePrimaryKeyCol(col: any): any {
    let singlePrimaryKeyCol = null;
    for (let i = 0; i < col.length; i++) {
        if (col[i].isPrimary) {
            singlePrimaryKeyCol = col[i];
            break;
        }
    }

    /* Add default id column to be returned */
    const defaultPrimaryKey = {
        name: "id",
        type: "Int!",
        isPrimary: true,
        isForeignKey: false
    }

    return singlePrimaryKeyCol ?? defaultPrimaryKey;
}


export function getColumnsWithoutForeignkey(col: any) {
    let result = [];
    for (let i = 0; i < col.length; i++) {
        if (col[i].isForeignKey) {
            continue;
        }
        result.push(col[i]);
    }
    return result;
}


//skips files and do not skip fk keys
export function skipExtraColumns(col: any) {
    let result = [];
    for (let i = 0; i < col.length; i++) {
        // if (col[i].isForeignKey || isFileType(col[i].type)){
        if (isFileType(col[i].type)) {
            continue;
        }
        result.push(col[i]);
    }
    return result;
}
