import { UITypes } from 'nocodb-sdk';
import { expect } from 'chai';
import request from 'supertest';
import { createTable, getAllTables } from '../../factory/table';
import { createBulkRows } from '../../factory/row';
import { createLtarColumn2, customColumns } from '../../factory/column';

async function ncAxiosLinkAdd({
  context,
  urlParams,
  body = {},
  status = 200,
  msg,
}: {
  context: { context: any; base: any };
  urlParams: { tableId: string; linkId: string; rowId: string };
  body?: any;
  status?: number;
  msg?: string;
}) {
  const url = `/api/v3/data/${context.base.id}/${urlParams.tableId}/links/${urlParams.linkId}/${urlParams.rowId}`;
  const response = await request(context.context.app)
    .post(url)
    .set('xc-auth', context.context.token)
    .send(body);

  expect(response.status).to.equal(status);
  if (msg) {
    expect(response.body.message || response.body.msg).to.equal(msg);
  }
  return response;
}

const data = {
  Customers: [
    {
      StoreId: 1,
      FirstName: 'MARY',
      LastName: 'SMITH',
      Email: 'MARY.SMITH@sakilacustomer.org',
      AddressId: 5,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'PATRICIA',
      LastName: 'JOHNSON',
      Email: 'PATRICIA.JOHNSON@sakilacustomer.org',
      AddressId: 6,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'LINDA',
      LastName: 'WILLIAMS',
      Email: 'LINDA.WILLIAMS@sakilacustomer.org',
      AddressId: 7,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'BARBARA',
      LastName: 'JONES',
      Email: 'BARBARA.JONES@sakilacustomer.org',
      AddressId: 8,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'ELIZABETH',
      LastName: 'BROWN',
      Email: 'ELIZABETH.BROWN@sakilacustomer.org',
      AddressId: 9,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'JENNIFER',
      LastName: 'DAVIS',
      Email: 'JENNIFER.DAVIS@sakilacustomer.org',
      AddressId: 10,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'MARIA',
      LastName: 'MILLER',
      Email: 'MARIA.MILLER@sakilacustomer.org',
      AddressId: 11,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'SUSAN',
      LastName: 'WILSON',
      Email: 'SUSAN.WILSON@sakilacustomer.org',
      AddressId: 12,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'MARGARET',
      LastName: 'MOORE',
      Email: 'MARGARET.MOORE@sakilacustomer.org',
      AddressId: 13,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'DOROTHY',
      LastName: 'TAYLOR',
      Email: 'DOROTHY.TAYLOR@sakilacustomer.org',
      AddressId: 14,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'LISA',
      LastName: 'ANDERSON',
      Email: 'LISA.ANDERSON@sakilacustomer.org',
      AddressId: 15,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'NANCY',
      LastName: 'THOMAS',
      Email: 'NANCY.THOMAS@sakilacustomer.org',
      AddressId: 16,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'KAREN',
      LastName: 'JACKSON',
      Email: 'KAREN.JACKSON@sakilacustomer.org',
      AddressId: 17,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'BETTY',
      LastName: 'WHITE',
      Email: 'BETTY.WHITE@sakilacustomer.org',
      AddressId: 18,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'HELEN',
      LastName: 'HARRIS',
      Email: 'HELEN.HARRIS@sakilacustomer.org',
      AddressId: 19,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'SANDRA',
      LastName: 'MARTIN',
      Email: 'SANDRA.MARTIN@sakilacustomer.org',
      AddressId: 20,
      Active: 0,
    },
    {
      StoreId: 1,
      FirstName: 'DONNA',
      LastName: 'THOMPSON',
      Email: 'DONNA.THOMPSON@sakilacustomer.org',
      AddressId: 21,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'CAROL',
      LastName: 'GARCIA',
      Email: 'CAROL.GARCIA@sakilacustomer.org',
      AddressId: 22,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'RUTH',
      LastName: 'MARTINEZ',
      Email: 'RUTH.MARTINEZ@sakilacustomer.org',
      AddressId: 23,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'SHARON',
      LastName: 'ROBINSON',
      Email: 'SHARON.ROBINSON@sakilacustomer.org',
      AddressId: 24,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'MICHELLE',
      LastName: 'CLARK',
      Email: 'MICHELLE.CLARK@sakilacustomer.org',
      AddressId: 25,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'LAURA',
      LastName: 'RODRIGUEZ',
      Email: 'LAURA.RODRIGUEZ@sakilacustomer.org',
      AddressId: 26,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'SARAH',
      LastName: 'LEWIS',
      Email: 'SARAH.LEWIS@sakilacustomer.org',
      AddressId: 27,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'KIMBERLY',
      LastName: 'LEE',
      Email: 'KIMBERLY.LEE@sakilacustomer.org',
      AddressId: 28,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'DEBORAH',
      LastName: 'WALKER',
      Email: 'DEBORAH.WALKER@sakilacustomer.org',
      AddressId: 29,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'JESSICA',
      LastName: 'HALL',
      Email: 'JESSICA.HALL@sakilacustomer.org',
      AddressId: 30,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'SHIRLEY',
      LastName: 'ALLEN',
      Email: 'SHIRLEY.ALLEN@sakilacustomer.org',
      AddressId: 31,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'CYNTHIA',
      LastName: 'YOUNG',
      Email: 'CYNTHIA.YOUNG@sakilacustomer.org',
      AddressId: 32,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'ANGELA',
      LastName: 'HERNANDEZ',
      Email: 'ANGELA.HERNANDEZ@sakilacustomer.org',
      AddressId: 33,
      Active: 1,
    },
    {
      StoreId: 1,
      FirstName: 'MELISSA',
      LastName: 'KING',
      Email: 'MELISSA.KING@sakilacustomer.org',
      AddressId: 34,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'AARON',
      LastName: 'SELBY',
      Email: 'AARON.SELBY@sakilacustomer.org',
      AddressId: 380,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'WILLIE',
      LastName: 'HOWEL',
      Email: 'WILLY.HOWEL@sakilacustomer.org',
      AddressId: 380,
      Active: 1,
    },
    {
      StoreId: 2,
      FirstName: 'WILLIE',
      LastName: 'ARKHAM',
      Email: 'WILLY.ARKHAM@sakilacustomer.org',
      AddressId: 380,
      Active: 1,
    },
  ],
  Films: [
    {
      FilmId: 1,
      Title: 'ACADEMY DINOSAUR',
      Description:
        'A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 0.99,
      Length: 86,
      ReplacementCost: 20.99,
      Rating: 'PG',
      SpecialFeatures: 'Deleted Scenes,Behind the Scenes',
    },
    {
      FilmId: 2,
      Title: 'ACE GOLDFINGER',
      Description:
        'A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 3,
      RentalRate: 4.99,
      Length: 48,
      ReplacementCost: 12.99,
      Rating: 'G',
      SpecialFeatures: 'Trailers,Deleted Scenes',
    },
    {
      FilmId: 3,
      Title: 'ADAPTATION HOLES',
      Description:
        'A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 7,
      RentalRate: 2.99,
      Length: 50,
      ReplacementCost: 18.99,
      Rating: 'NC-17',
      SpecialFeatures: 'Trailers,Deleted Scenes',
    },
    {
      FilmId: 4,
      Title: 'AFFAIR PREJUDICE',
      Description:
        'A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 5,
      RentalRate: 2.99,
      Length: 117,
      ReplacementCost: 26.99,
      Rating: 'G',
      SpecialFeatures: 'Commentaries,Behind the Scenes',
    },
    {
      FilmId: 5,
      Title: 'AFRICAN EGG',
      Description:
        'A Fast-Paced Documentary of a Pastry Chef And a Dentist who must Pursue a Forensic Psychologist in The Gulf of Mexico',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 2.99,
      Length: 130,
      ReplacementCost: 22.99,
      Rating: 'G',
      SpecialFeatures: 'Deleted Scenes',
    },
    {
      FilmId: 6,
      Title: 'AGENT TRUMAN',
      Description:
        'A Intrepid Panorama of a Robot And a Boy who must Escape a Sumo Wrestler in Ancient China',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 3,
      RentalRate: 2.99,
      Length: 169,
      ReplacementCost: 17.99,
      Rating: 'PG',
      SpecialFeatures: 'Deleted Scenes',
    },
    {
      FilmId: 7,
      Title: 'AIRPLANE SIERRA',
      Description:
        'A Touching Saga of a Hunter And a Butler who must Discover a Butler in A Jet Boat',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 4.99,
      Length: 62,
      ReplacementCost: 28.99,
      Rating: 'PG-13',
      SpecialFeatures: 'Trailers,Deleted Scenes',
    },
    {
      FilmId: 8,
      Title: 'AIRPORT POLLOCK',
      Description:
        'A Epic Tale of a Moose And a Girl who must Confront a Monkey in Ancient India',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 4.99,
      Length: 54,
      ReplacementCost: 15.99,
      Rating: 'R',
      SpecialFeatures: 'Trailers',
    },
    {
      FilmId: 9,
      Title: 'ALABAMA DEVIL',
      Description:
        'A Thoughtful Panorama of a Database Administrator And a Mad Scientist who must Outgun a Mad Scientist in A Jet Boat',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 3,
      RentalRate: 2.99,
      Length: 114,
      ReplacementCost: 21.99,
      Rating: 'PG-13',
      SpecialFeatures: 'Trailers,Deleted Scenes',
    },
    {
      FilmId: 10,
      Title: 'ALADDIN CALENDAR',
      Description:
        'A Action-Packed Tale of a Man And a Lumberjack who must Reach a Feminist in Ancient China',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 4.99,
      Length: 63,
      ReplacementCost: 24.99,
      Rating: 'NC-17',
      SpecialFeatures: 'Trailers,Deleted Scenes',
    },
    {
      FilmId: 11,
      Title: 'ALAMO VIDEOTAPE',
      Description:
        'A Boring Epistle of a Butler And a Cat who must Fight a Pastry Chef in A MySQL Convention',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 0.99,
      Length: 126,
      ReplacementCost: 16.99,
      Rating: 'G',
      SpecialFeatures: 'Commentaries,Behind the Scenes',
    },
    {
      FilmId: 12,
      Title: 'ALASKA PHANTOM',
      Description:
        'A Fanciful Saga of a Hunter And a Pastry Chef who must Vanquish a Boy in Australia',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 0.99,
      Length: 136,
      ReplacementCost: 22.99,
      Rating: 'PG',
      SpecialFeatures: 'Commentaries,Deleted Scenes',
    },
    {
      FilmId: 13,
      Title: 'ALI FOREVER',
      Description:
        'A Action-Packed Drama of a Dentist And a Crocodile who must Battle a Feminist in The Canadian Rockies',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 4,
      RentalRate: 4.99,
      Length: 150,
      ReplacementCost: 21.99,
      Rating: 'PG',
      SpecialFeatures: 'Deleted Scenes,Behind the Scenes',
    },
    {
      FilmId: 14,
      Title: 'ALICE FANTASIA',
      Description:
        'A Emotional Drama of a A Shark And a Database Administrator who must Vanquish a Pioneer in Soviet Georgia',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 0.99,
      Length: 94,
      ReplacementCost: 23.99,
      Rating: 'NC-17',
      SpecialFeatures: 'Trailers,Deleted Scenes,Behind the Scenes',
    },
    {
      FilmId: 15,
      Title: 'ALIEN CENTER',
      Description:
        'A Brilliant Drama of a Cat And a Mad Scientist who must Battle a Feminist in A MySQL Convention',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 5,
      RentalRate: 2.99,
      Length: 46,
      ReplacementCost: 10.99,
      Rating: 'NC-17',
      SpecialFeatures: 'Trailers,Commentaries,Behind the Scenes',
    },
    {
      FilmId: 16,
      Title: 'ALLEY EVOLUTION',
      Description:
        'A Fast-Paced Drama of a Robot And a Composer who must Battle a Astronaut in New Orleans',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 2.99,
      Length: 180,
      ReplacementCost: 23.99,
      Rating: 'NC-17',
      SpecialFeatures: 'Trailers,Commentaries',
    },
    {
      FilmId: 17,
      Title: 'ALONE TRIP',
      Description:
        'A Fast-Paced Character Study of a Composer And a Dog who must Outgun a Boat in An Abandoned Fun House',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 3,
      RentalRate: 0.99,
      Length: 82,
      ReplacementCost: 14.99,
      Rating: 'R',
      SpecialFeatures: 'Trailers,Behind the Scenes',
    },
    {
      FilmId: 18,
      Title: 'ALTER VICTORY',
      Description:
        'A Thoughtful Drama of a Composer And a Feminist who must Meet a Secret Agent in The Canadian Rockies',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 0.99,
      Length: 57,
      ReplacementCost: 27.99,
      Rating: 'PG-13',
      SpecialFeatures: 'Trailers,Behind the Scenes',
    },
    {
      FilmId: 19,
      Title: 'AMADEUS HOLY',
      Description:
        'A Emotional Display of a Pioneer And a Technical Writer who must Battle a Man in A Baloon',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 0.99,
      Length: 113,
      ReplacementCost: 20.99,
      Rating: 'PG',
      SpecialFeatures: 'Commentaries,Deleted Scenes,Behind the Scenes',
    },
    {
      FilmId: 20,
      Title: 'AMELIE HELLFIGHTERS',
      Description:
        'A Boring Drama of a Woman And a Squirrel who must Conquer a Student in A Baloon',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 4,
      RentalRate: 4.99,
      Length: 79,
      ReplacementCost: 23.99,
      Rating: 'R',
      SpecialFeatures: 'Commentaries,Deleted Scenes,Behind the Scenes',
    },
    {
      FilmId: 21,
      Title: 'AMERICAN CIRCUS',
      Description:
        'A Insightful Drama of a Girl And a Astronaut who must Face a Database Administrator in A Shark Tank',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 3,
      RentalRate: 4.99,
      Length: 129,
      ReplacementCost: 17.99,
      Rating: 'R',
      SpecialFeatures: 'Commentaries,Behind the Scenes',
    },
    {
      FilmId: 22,
      Title: 'AMISTAD MIDSUMMER',
      Description:
        'A Emotional Character Study of a Dentist And a Crocodile who must Meet a Sumo Wrestler in California',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 2.99,
      Length: 85,
      ReplacementCost: 10.99,
      Rating: 'G',
      SpecialFeatures: 'Commentaries,Behind the Scenes',
    },
    {
      FilmId: 23,
      Title: 'ANACONDA CONFESSIONS',
      Description:
        'A Lacklusture Display of a Dentist And a Dentist who must Fight a Girl in Australia',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 3,
      RentalRate: 0.99,
      Length: 92,
      ReplacementCost: 9.99,
      Rating: 'R',
      SpecialFeatures: 'Trailers,Deleted Scenes',
    },
    {
      FilmId: 24,
      Title: 'ANALYZE HOOSIERS',
      Description:
        'A Thoughtful Display of a Explorer And a Pastry Chef who must Overcome a Feminist in The Sahara Desert',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 6,
      RentalRate: 2.99,
      Length: 181,
      ReplacementCost: 19.99,
      Rating: 'R',
      SpecialFeatures: 'Trailers,Behind the Scenes',
    },
    {
      FilmId: 25,
      Title: 'ANGELS LIFE',
      Description:
        'A Thoughtful Display of a Woman And a Astronaut who must Battle a Robot in Berlin',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 3,
      RentalRate: 2.99,
      Length: 74,
      ReplacementCost: 15.99,
      Rating: 'G',
      SpecialFeatures: 'Trailers',
    },
    {
      FilmId: 26,
      Title: 'ANNIE IDENTITY',
      Description:
        'A Amazing Panorama of a Pastry Chef And a Boat who must Escape a Woman in An Abandoned Amusement Park',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 3,
      RentalRate: 0.99,
      Length: 86,
      ReplacementCost: 15.99,
      Rating: 'G',
      SpecialFeatures: 'Commentaries,Deleted Scenes',
    },
    {
      FilmId: 27,
      Title: 'ANONYMOUS HUMAN',
      Description:
        'A Amazing Reflection of a Database Administrator And a Astronaut who must Outrace a Database Administrator in A Shark Tank',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 7,
      RentalRate: 0.99,
      Length: 179,
      ReplacementCost: 12.99,
      Rating: 'NC-17',
      SpecialFeatures: 'Deleted Scenes,Behind the Scenes',
    },
    {
      FilmId: 28,
      Title: 'ANTHEM LUKE',
      Description:
        'A Touching Panorama of a Waitress And a Woman who must Outrace a Dog in An Abandoned Amusement Park',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 5,
      RentalRate: 4.99,
      Length: 91,
      ReplacementCost: 16.99,
      Rating: 'PG-13',
      SpecialFeatures: 'Deleted Scenes,Behind the Scenes',
    },
    {
      FilmId: 29,
      Title: 'ANTITRUST TOMATOES',
      Description:
        'A Fateful Yarn of a Womanizer And a Feminist who must Succumb a Database Administrator in Ancient India',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 5,
      RentalRate: 2.99,
      Length: 168,
      ReplacementCost: 11.99,
      Rating: 'NC-17',
      SpecialFeatures: 'Trailers,Commentaries,Deleted Scenes',
    },
    {
      FilmId: 30,
      Title: 'ANYTHING SAVANNAH',
      Description:
        'A Epic Story of a Pastry Chef And a Woman who must Chase a Feminist in An Abandoned Fun House',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 4,
      RentalRate: 2.99,
      Length: 82,
      ReplacementCost: 27.99,
      Rating: 'R',
      SpecialFeatures: 'Trailers,Deleted Scenes,Behind the Scenes',
    },
    {
      FilmId: 31,
      Title: 'WORST BANGER',
      Description:
        'A Thrilling Drama of a Madman And a Dentist who must Conquer a Boy in The Outback',
      ReleaseYear: 2006,
      LanguageId: 1,
      OriginalLanguageId: null,
      RentalDuration: 4,
      RentalRate: 2.99,
      Length: 185,
      ReplacementCost: 26.99,
      Rating: 'PG',
      SpecialFeatures: 'Deleted Scenes,Behind the Scenes',
    },
  ],
  Rentals: [
    {
      RentalId: 1,
      RentalDate: '2005-05-24T22:53:30.000',
      InventoryId: '367',
      CustomerId: '130',
      ReturnDate: '2005-05-26T22:04:30.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 2,
      RentalDate: '2005-05-24T22:54:33.000',
      InventoryId: '1525',
      CustomerId: '459',
      ReturnDate: '2005-05-28T19:40:33.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 3,
      RentalDate: '2005-05-24T23:03:39.000',
      InventoryId: '1711',
      CustomerId: '408',
      ReturnDate: '2005-06-01T22:12:39.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 4,
      RentalDate: '2005-05-24T23:04:41.000',
      InventoryId: '2452',
      CustomerId: '333',
      ReturnDate: '2005-06-03T01:43:41.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 5,
      RentalDate: '2005-05-24T23:05:21.000',
      InventoryId: '2079',
      CustomerId: '222',
      ReturnDate: '2005-06-02T04:33:21.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 6,
      RentalDate: '2005-05-24T23:08:07.000',
      InventoryId: '2792',
      CustomerId: '549',
      ReturnDate: '2005-05-27T01:32:07.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 7,
      RentalDate: '2005-05-24T23:11:53.000',
      InventoryId: '3995',
      CustomerId: '269',
      ReturnDate: '2005-05-29T20:34:53.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 8,
      RentalDate: '2005-05-24T23:31:46.000',
      InventoryId: '2346',
      CustomerId: '239',
      ReturnDate: '2005-05-27T23:33:46.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 9,
      RentalDate: '2005-05-25T00:00:40.000',
      InventoryId: '2580',
      CustomerId: '126',
      ReturnDate: '2005-05-28T00:22:40.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 10,
      RentalDate: '2005-05-25T00:02:21.000',
      InventoryId: '1824',
      CustomerId: '399',
      ReturnDate: '2005-05-31T22:44:21.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 11,
      RentalDate: '2005-05-25T00:09:02.000',
      InventoryId: '4443',
      CustomerId: '142',
      ReturnDate: '2005-06-02T20:56:02.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 12,
      RentalDate: '2005-05-25T00:19:27.000',
      InventoryId: '1584',
      CustomerId: '261',
      ReturnDate: '2005-05-30T05:44:27.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 13,
      RentalDate: '2005-05-25T00:22:55.000',
      InventoryId: '2294',
      CustomerId: '334',
      ReturnDate: '2005-05-30T04:28:55.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 14,
      RentalDate: '2005-05-25T00:31:15.000',
      InventoryId: '2701',
      CustomerId: '446',
      ReturnDate: '2005-05-26T02:56:15.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: 15,
      RentalDate: '2005-05-25T00:39:22.000',
      InventoryId: '3049',
      CustomerId: '319',
      ReturnDate: '2005-06-03T03:30:22.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '16',
      RentalDate: '2005-05-25T00:43:11.000',
      InventoryId: '389',
      CustomerId: '316',
      ReturnDate: '2005-05-26T04:42:11.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '17',
      RentalDate: '2005-05-25T01:06:36.000',
      InventoryId: '830',
      CustomerId: '575',
      ReturnDate: '2005-05-27T00:43:36.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '18',
      RentalDate: '2005-05-25T01:10:47.000',
      InventoryId: '3376',
      CustomerId: '19',
      ReturnDate: '2005-05-31T06:35:47.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '19',
      RentalDate: '2005-05-25T01:17:24.000',
      InventoryId: '1941',
      CustomerId: '456',
      ReturnDate: '2005-05-31T06:00:24.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '20',
      RentalDate: '2005-05-25T01:48:41.000',
      InventoryId: '3517',
      CustomerId: '185',
      ReturnDate: '2005-05-27T02:20:41.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '21',
      RentalDate: '2005-05-25T01:59:46.000',
      InventoryId: '146',
      CustomerId: '388',
      ReturnDate: '2005-05-26T01:01:46.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '22',
      RentalDate: '2005-05-25T02:19:23.000',
      InventoryId: '727',
      CustomerId: '509',
      ReturnDate: '2005-05-26T04:52:23.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '23',
      RentalDate: '2005-05-25T02:40:21.000',
      InventoryId: '4441',
      CustomerId: '438',
      ReturnDate: '2005-05-29T06:34:21.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '24',
      RentalDate: '2005-05-25T02:53:02.000',
      InventoryId: '3273',
      CustomerId: '350',
      ReturnDate: '2005-05-27T01:15:02.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '25',
      RentalDate: '2005-05-25T03:21:20.000',
      InventoryId: '3961',
      CustomerId: '37',
      ReturnDate: '2005-05-27T21:25:20.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '26',
      RentalDate: '2005-05-25T03:36:50.000',
      InventoryId: '4371',
      CustomerId: '371',
      ReturnDate: '2005-05-31T00:34:50.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '27',
      RentalDate: '2005-05-25T03:41:50.000',
      InventoryId: '1225',
      CustomerId: '301',
      ReturnDate: '2005-05-30T01:13:50.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '28',
      RentalDate: '2005-05-25T03:42:37.000',
      InventoryId: '4068',
      CustomerId: '232',
      ReturnDate: '2005-05-26T09:26:37.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '29',
      RentalDate: '2005-05-25T03:47:12.000',
      InventoryId: '611',
      CustomerId: '44',
      ReturnDate: '2005-05-30T00:31:12.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '30',
      RentalDate: '2005-05-25T04:01:32.000',
      InventoryId: '3744',
      CustomerId: '430',
      ReturnDate: '2005-05-30T03:12:32.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '31',
      RentalDate: '2005-05-25T04:05:17.000',
      InventoryId: '4482',
      CustomerId: '369',
      ReturnDate: '2005-05-30T07:15:17.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '32',
      RentalDate: '2005-05-25T04:06:21.000',
      InventoryId: '3832',
      CustomerId: '230',
      ReturnDate: '2005-05-25T23:55:21.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '33',
      RentalDate: '2005-05-25T04:18:51.000',
      InventoryId: '1681',
      CustomerId: '272',
      ReturnDate: '2005-05-27T03:58:51.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '34',
      RentalDate: '2005-05-25T04:19:28.000',
      InventoryId: '2613',
      CustomerId: '597',
      ReturnDate: '2005-05-29T00:10:28.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '35',
      RentalDate: '2005-05-25T04:24:36.000',
      InventoryId: '1286',
      CustomerId: '484',
      ReturnDate: '2005-05-27T07:02:36.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '36',
      RentalDate: '2005-05-25T04:36:26.000',
      InventoryId: '1308',
      CustomerId: '88',
      ReturnDate: '2005-05-29T00:31:26.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '37',
      RentalDate: '2005-05-25T04:44:31.000',
      InventoryId: '403',
      CustomerId: '535',
      ReturnDate: '2005-05-29T01:03:31.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '38',
      RentalDate: '2005-05-25T04:47:44.000',
      InventoryId: '2540',
      CustomerId: '302',
      ReturnDate: '2005-06-01T00:58:44.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '39',
      RentalDate: '2005-05-25T04:51:46.000',
      InventoryId: '4466',
      CustomerId: '207',
      ReturnDate: '2005-05-31T03:14:46.000',
      StaffId: '2',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
    {
      RentalId: '40',
      RentalDate: '2005-05-25T05:09:04.000',
      InventoryId: '2638',
      CustomerId: '413',
      ReturnDate: '2005-05-27T23:12:04.000',
      StaffId: '1',
      LastUpdate: '2006-02-15T21:30:53.000',
    },
  ],
};

export const initCustomerTable = async (context: any, base: any) => {
  const customerTable = await createTable(context, base, {
    title: 'Customer',
    table_name: 'customer',
    columns: customColumns('custom', [
      {
        title: 'StoreId',
        column_name: 'store_id',
        uidt: UITypes.Number,
      },
      {
        title: 'FirstName',
        column_name: 'first_name',
        uidt: UITypes.SingleLineText,
      },
      {
        title: 'LastName',
        column_name: 'last_name',
        uidt: UITypes.SingleLineText,
      },
      {
        title: 'Email',
        column_name: 'email',
        uidt: UITypes.Email,
      },
      {
        title: 'AddressId',
        column_name: 'address_id',
        uidt: UITypes.Number,
      },
      {
        title: 'Active',
        column_name: 'active',
        uidt: UITypes.Number,
      },
    ]),
  });

  await createBulkRows(context, {
    base: base,
    table: customerTable,
    values: data.Customers,
  });

  return customerTable;
};

export const initFilmTable = async (context: any, base: any) => {
  const filmTable = await createTable(context, base, {
    title: 'Film',
    table_name: 'film',
    columns: [
      {
        title: 'FilmId',
        column_name: 'film_id',
        uidt: UITypes.ID,
        pk: true,
      },
      {
        title: 'Title',
        column_name: 'title',
        uidt: UITypes.SingleLineText,
      },
      {
        title: 'Description',
        column_name: 'description',
        uidt: UITypes.LongText,
      },
      {
        title: 'ReleaseYear',
        column_name: 'release_year',
        uidt: UITypes.SingleLineText,
      },
      {
        title: 'LanguageId',
        column_name: 'language_id',
        uidt: UITypes.Number,
      },
      {
        title: 'OriginalLanguageId',
        column_name: 'original_language_id',
        uidt: UITypes.Number,
      },
      {
        title: 'RentalDuration',
        column_name: 'rental_duration',
        uidt: UITypes.Number,
      },
      {
        title: 'RentalRate',
        column_name: 'rental_rate',
        uidt: UITypes.Decimal,
      },
      {
        title: 'Length',
        column_name: 'length',
        uidt: UITypes.Number,
      },
      {
        title: 'ReplacementCost',
        column_name: 'replacement_cost',
        uidt: UITypes.Decimal,
      },
      {
        title: 'Rating',
        column_name: 'rating',
        uidt: UITypes.SingleSelect,
        dtxp: "'G','PG','PG-13','R','NC-17'",
      },
      {
        title: 'SpecialFeatures',
        column_name: 'special_features',
        uidt: UITypes.SingleLineText,
      },
      {
        title: 'LastUpdate',
        column_name: 'last_update',
        uidt: UITypes.DateTime,
      },
    ],
  });

  await createBulkRows(context, {
    base: base,
    table: filmTable,
    values: data.Films,
  });

  return filmTable;
};

export const initRentalTable = async (context: any, base: any) => {
  const rentalTable = await createTable(context, base, {
    title: 'Rental',
    table_name: 'rental',
    columns: customColumns('custom', [
      {
        column_name: 'rental_date',
        title: 'RentalDate',
        type: UITypes.DateTime,
      },
      {
        column_name: 'inventory_id',
        title: 'InventoryId',
        type: UITypes.Number,
      },
      {
        column_name: 'customer_id',
        title: 'CustomerId',
        type: UITypes.Number,
      },
      {
        column_name: 'return_date',
        title: 'ReturnDate',
        type: UITypes.DateTime,
      },
      {
        column_name: 'staff_id',
        title: 'StaffId',
        type: UITypes.Number,
      },
      {
        column_name: 'last_update',
        title: 'LastUpdate',
        type: UITypes.DateTime,
      },
    ]),
  });

  await createBulkRows(context, {
    base: base,
    table: rentalTable,
    values: data.Rentals,
  });

  return rentalTable;
};

export const linkInitTables = async (context: any, base: any) => {
  const allTables = await getAllTables({ base });
  const customerTable = allTables.find((tbl) => tbl.title === 'Customer');
  const rentalTable = allTables.find((tbl) => tbl.title === 'Rental');
  const Customer_MM_Rental_LTAR = await createLtarColumn2(context, {
    title: 'Rentals',
    parentTable: customerTable!,
    childTable: rentalTable!,
    type: 'mm',
  });

  const rentalCustomerLink = [
    {
      id: '1',
      customerId: '30',
    },
    {
      id: '2',
      customerId: '29',
    },
    {
      id: '3',
      customerId: '28',
    },
    {
      id: '4',
      customerId: '27',
    },
    {
      id: '5',
      customerId: '26',
    },
    {
      id: '6',
      customerId: '25',
    },
    {
      id: '7',
      customerId: '24',
    },
    {
      id: '8',
      customerId: '23',
    },
    {
      id: '9',
      customerId: '22',
    },
    {
      id: '10',
      customerId: '21',
    },
    {
      id: '11',
      customerId: '20',
    },
    {
      id: '12',
      customerId: '19',
    },
    {
      id: '13',
      customerId: '18',
    },
    {
      id: '14',
      customerId: '17',
    },
    {
      id: '15',
      customerId: '16',
    },
    {
      id: '16',
      customerId: '15',
    },
    {
      id: '17',
      customerId: '14',
    },
    {
      id: '18',
      customerId: '13',
    },
    {
      id: '19',
      customerId: '12',
    },
    {
      id: '20',
      customerId: '11',
    },
    {
      id: '21',
      customerId: '10',
    },
    {
      id: '22',
      customerId: '9',
    },
    {
      id: '23',
      customerId: '8',
    },
    {
      id: '24',
      customerId: '7',
    },
    {
      id: '25',
      customerId: '6',
    },
    {
      id: '26',
      customerId: '5',
    },
    {
      id: '1',
      customerId: '4',
    },
    {
      id: '1',
      customerId: '3',
    },
    {
      id: '1',
      customerId: '2',
    },
    {
      id: '1',
      customerId: '1',
    },
    {
      id: '4',
      customerId: '7',
    },
    {
      id: '4',
      customerId: '8',
    },
    {
      id: '4',
      customerId: '9',
    },
    {
      id: '4',
      customerId: '10',
    },
    {
      id: '5',
      customerId: '11',
    },
    {
      id: '5',
      customerId: '12',
    },
  ];

  const linkTo_Customer_MM_Rental_LTAR = (rowId: string, body: any[]) => {
    return ncAxiosLinkAdd({
      context: {
        context,
        base,
      },
      urlParams: {
        tableId: customerTable!.id,
        linkId: Customer_MM_Rental_LTAR.id,
        rowId: rowId,
      },
      body: body,
      status: 200,
    });
  };
  await Promise.all(
    rentalCustomerLink.map((link) =>
      linkTo_Customer_MM_Rental_LTAR(link.customerId, [
        { id: Number(link.id) },
      ]),
    ),
  );
};
