-----внесување во табелата Genre
INSERT INTO public.Genre (name, description)
SELECT
    genre,
    'Description for ' || genre
FROM unnest(ARRAY[
    'Action','Comedy','Drama','Horror','Sci-Fi',
    'Romance','Thriller','Animation','Documentary','Fantasy',
    'Mystery','Adventure','Crime','Biography','History',
    'Music','Sport','War','Western','Family'
]) AS genre;
-----внесување во табелата Movie со вистински филмови
INSERT INTO Movie (title, release_year, duration, language, description)
VALUES
('The Shawshank Redemption',    1994, 142, 'English',  'Two imprisoned men bond over years.'),
('The Godfather',               1972, 175, 'English',  'The aging patriarch of a crime dynasty.'),
('The Dark Knight',             2008, 152, 'English',  'Batman faces the Joker in Gotham.'),
('Schindlers List',             1993, 195, 'English',  'A businessman saves Jewish refugees.'),
('The Lord of the Rings: The Return of the King', 2003, 201, 'English', 'The final battle for Middle-earth.'),
('Pulp Fiction',                1994, 154, 'English',  'Interconnected stories of crime in LA.'),
('Forrest Gump',                1994, 142, 'English',  'Life is like a box of chocolates.'),
('Inception',                   2010, 148, 'English',  'A thief enters dreams to steal secrets.'),
('The Matrix',                  1999, 136, 'English',  'A hacker discovers a simulated reality.'),
('Goodfellas',                  1990, 146, 'English',  'Rise and fall of a mob associate.'),
('Interstellar',                2014, 169, 'English',  'Astronauts travel through a wormhole.'),
('The Silence of the Lambs',    1991, 118, 'English',  'An FBI agent seeks help from Hannibal Lecter.'),
('Saving Private Ryan',         1998, 169, 'English',  'WWII soldiers search for a paratrooper.'),
('Gladiator',                   2000, 155, 'English',  'A Roman general seeks revenge as a slave.'),
('The Lion King',               1994,  88, 'English',  'A lion cub flees and reclaims his kingdom.'),
('Titanic',                     1997, 194, 'English',  'A love story aboard a doomed ship.'),
('Jurassic Park',               1993, 127, 'English',  'Dinosaurs run amok on an island.'),
('The Avengers',                2012, 143, 'English',  'Superheroes unite to save the world.'),
('Avatar',                      2009, 162, 'English',  'A marine on an alien planet.'),
('Fight Club',                  1999, 139, 'English',  'An insomniac forms an underground club.'),
('The Prestige',                2006, 130, 'English',  'Two magicians enter a dangerous rivalry.'),
('Whiplash',                    2014, 107, 'English',  'A drummer pursues greatness at any cost.'),
('The Grand Budapest Hotel',    2014,  99, 'English',  'Adventures of a legendary concierge.'),
('Mad Max: Fury Road',          2015, 120, 'English',  'A chase across a post-apocalyptic wasteland.'),
('The Revenant',                2015, 156, 'English',  'A frontiersman on a quest for survival.'),
('Parasite',                    2019, 132, 'Korean',   'A poor family infiltrates a wealthy household.'),
('Spirited Away',               2001, 125, 'Japanese', 'A girl trapped in a spirit world.'),
('Your Name',                   2016, 106, 'Japanese', 'Two strangers swap bodies mysteriously.'),
('Oldboy',                      2003, 120, 'Korean',   'A man is imprisoned for fifteen years.'),
('Amelie',                      2001, 122, 'French',   'A shy waitress improves others lives.'),
('City of God',                 2002, 130, 'Spanish',  'Growing up amid violence in Rio.'),
('Pan''s Labyrinth',            2006, 118, 'Spanish',  'A girl escapes into a dark fantasy.'),
('The Intouchables',            2011, 112, 'French',   'An unlikely friendship between opposites.'),
('Cinema Paradiso',             1988, 155, 'Italian',  'A filmmaker recalls his childhood love of film.'),
('Life is Beautiful',           1997, 116, 'Italian',  'A father shields his son from the Holocaust.'),
('Das Boot',                    1981, 149, 'German',   'A German submarine crew in WWII.'),
('Run Lola Run',                1998,  81, 'German',   'A woman races to save her boyfriend.'),
('Crouching Tiger Hidden Dragon',2000, 120, 'Chinese', 'Warriors battle over a stolen sword.'),
('Hero',                        2002,  99, 'Chinese',  'An assassin tells the story of his mission.'),
('Lagaan',                      2001, 224, 'Hindi',    'Villagers challenge colonial rulers to cricket.'),
('3 Idiots',                    2009, 170, 'Hindi',    'Three friends navigate engineering college.'),
('No Country for Old Men',      2007, 122, 'English',  'A hunter stumbles upon drug money.'),
('There Will Be Blood',         2007, 158, 'English',  'An oilman''s obsession destroys everything.'),
('Eternal Sunshine of the Spotless Mind', 2004, 108, 'English', 'A couple erases memories of each other.'),
('Requiem for a Dream',         2000, 102, 'English',  'Four people spiral into addiction.'),
('Black Swan',                  2010, 108, 'English',  'A ballerina descends into madness.'),
('Birdman',                     2014, 119, 'English',  'A faded superhero actor seeks redemption.'),
('12 Years a Slave',            2013, 134, 'English',  'A free Black man is enslaved.'),
('The Wolf of Wall Street',     2013, 180, 'English',  'A stockbroker''s rise and fall.'),
('Django Unchained',            2012, 165, 'English',  'A freed slave hunts down his wife.'),
('Inglourious Basterds',        2009, 153, 'English',  'A plot to assassinate Nazi leaders.'),
('Once Upon a Time in Hollywood', 2019, 161, 'English', 'An actor navigates 1960s Hollywood.'),
('Joker',                       2019, 122, 'English',  'The origin of Batman''s greatest enemy.'),
('1917',                        2019, 119, 'English',  'Two soldiers cross enemy lines in WWI.'),
('Dunkirk',                     2017, 106, 'English',  'The evacuation of Dunkirk in WWII.'),
('Arrival',                     2016, 116, 'English',  'A linguist deciphers alien language.'),
('Ex Machina',                  2014, 108, 'English',  'A programmer tests an AI robot.'),
('Her',                         2013, 126, 'English',  'A man falls in love with an AI.'),
('Blade Runner 2049',           2017, 164, 'English',  'A blade runner uncovers a secret.'),
('The Shape of Water',          2017, 123, 'English',  'A mute woman falls for a sea creature.'),
('Three Billboards Outside Ebbing', 2017, 115, 'English', 'A mother challenges police inaction.'),
('Get Out',                     2017, 104, 'English',  'A Black man uncovers a terrifying secret.'),
('Hereditary',                  2018, 127, 'English',  'A family unravels dark secrets after a death.'),
('Midsommar',                   2019, 148, 'English',  'A couple travels to a Swedish midsummer festival.'),
('A Quiet Place',               2018,  90, 'English',  'A family survives in silence.'),
('Bird Box',                    2018, 124, 'English',  'Creatures drive people to madness.'),
('The Witch',                   2015,  92, 'English',  'A puritan family encounters evil in the woods.'),
('It',                          2017, 135, 'English',  'Children face a shapeshifting monster.'),
('Doctor Strange',              2016, 115, 'English',  'A surgeon becomes a sorcerer.'),
('Black Panther',               2018, 134, 'English',  'The king of Wakanda fights for his throne.'),
('Avengers: Infinity War',      2018, 149, 'English',  'Heroes battle Thanos for the Infinity Stones.'),
('Avengers: Endgame',           2019, 181, 'English',  'The Avengers reverse Thanos''s actions.'),
('Spider-Man: Into the Spider-Verse', 2018, 117, 'English', 'Miles Morales becomes Spider-Man.'),
('Coco',                        2017, 105, 'English',  'A boy visits the Land of the Dead.'),
('Soul',                        2020, 100, 'English',  'A jazz musician journeys to the soul world.'),
('Up',                          2009,  96, 'English',  'An old man flies his house with balloons.'),
('WALL-E',                      2008,  98, 'English',  'A robot falls in love in a ruined Earth.'),
('Toy Story',                   1995,  81, 'English',  'Toys come alive when humans leave.'),
('Finding Nemo',                2003, 100, 'English',  'A father searches for his lost son.'),
('The Incredibles',             2004, 115, 'English',  'A family of superheroes saves the world.'),
('Shrek',                       2001,  90, 'English',  'An ogre rescues a princess.'),
('Frozen',                      2013, 102, 'English',  'A princess seeks her ice-powered sister.'),
('Moana',                       2016, 107, 'English',  'A girl sails to save her island.'),
('Ratatouille',                 2007, 111, 'English',  'A rat dreams of becoming a chef.'),
('Inside Out',                  2015,  95, 'English',  'Emotions guide a girl through change.'),
('The Good the Bad and the Ugly', 1966, 178, 'Italian', 'Three men search for buried gold.'),
('Once Upon a Time in the West', 1968, 165, 'Italian', 'A mysterious stranger seeks revenge.'),
('Apocalypse Now',              1979, 147, 'English',  'A captain hunts a rogue colonel in Vietnam.'),
('Full Metal Jacket',           1987, 116, 'English',  'Marines train for and fight in Vietnam.'),
('Platoon',                     1986, 120, 'English',  'A soldier''s moral struggle in Vietnam.'),
('The Deer Hunter',             1978, 183, 'English',  'Friends cope after the Vietnam War.'),
('One Flew Over the Cuckoos Nest', 1975, 133, 'English', 'A criminal feigns insanity in a mental ward.'),
('Chinatown',                   1974, 130, 'English',  'A private eye uncovers corruption in LA.'),
('Taxi Driver',                 1976, 114, 'English',  'A disturbed cab driver takes justice into his hands.'),
('Raging Bull',                 1980, 129, 'English',  'The rise and fall of boxer Jake LaMotta.'),
('Scarface',                    1983, 170, 'English',  'A Cuban refugee builds a drug empire.'),
('The Departed',                2006, 151, 'English',  'Cops and criminals infiltrate each other.'),
('Heat',                        1995, 170, 'English',  'A detective hunts a master thief.'),
('L.A. Confidential',           1997, 138, 'English',  'Corruption in 1950s Los Angeles.'),
('Memento',                     2000, 113, 'English',  'A man with no short-term memory hunts a killer.'),
('Se7en',                       1995, 127, 'English',  'Detectives track a serial killer.'),
('Zodiac',                      2007, 157, 'English',  'Journalists hunt the Zodiac Killer.'),
('Prisoners',                   2013, 153, 'English',  'A father searches for his kidnapped daughter.'),
('Gone Girl',                   2014, 149, 'English',  'A man becomes a suspect in his wife''s disappearance.'),
('Nightcrawler',                2014, 117, 'English',  'A freelance crime journalist crosses lines.'),
('Drive',                       2011, 100, 'English',  'A stunt driver moonlights as a getaway driver.'),
('Only God Forgives',           2013,  90, 'English',  'A drug smuggler seeks revenge in Bangkok.'),
('Lost in Translation',         2003, 102, 'English',  'Two Americans bond in Tokyo.'),
('The Virgin Suicides',         1999,  97, 'English',  'Neighbors recall five mysterious sisters.'),
('Marie Antoinette',            2006, 123, 'English',  'The life of the famous French queen.'),
('Almost Famous',               2000, 122, 'English',  'A teenager writes for Rolling Stone magazine.'),
('Boogie Nights',               1997, 155, 'English',  'The rise and fall of a porn star.'),
('Magnolia',                    1999, 188, 'English',  'Interconnected stories in the San Fernando Valley.'),
('Short Cuts',                  1993, 187, 'English',  'Interwoven tales of suburban life.'),
('Nashville',                   1975, 160, 'English',  'Twenty-four characters converge in Nashville.'),
('The Tree of Life',            2011, 139, 'English',  'A family''s journey through grace and nature.'),
('Badlands',                    1973,  94, 'English',  'A teenage girl and her killer boyfriend flee.'),
('Days of Heaven',              1978,  95, 'English',  'A farm worker''s love triangle ends in tragedy.'),
('Blue Velvet',                 1986, 120, 'English',  'A student discovers a dark underworld.'),
('Mulholland Drive',            2001, 147, 'English',  'An actress navigates a surreal Hollywood nightmare.'),
('Eraserhead',                  1977,  89, 'English',  'A man struggles with an unwanted child.'),
('2001 A Space Odyssey',        1968, 149, 'English',  'Astronauts travel to Jupiter with a mysterious AI.'),
('A Clockwork Orange',          1971, 136, 'English',  'A violent criminal undergoes aversion therapy.'),
('The Shining',                 1980, 146, 'English',  'A writer descends into madness in a hotel.'),
('Eyes Wide Shut',              1999, 159, 'English',  'A doctor enters a secret erotic society.'),
('Barry Lyndon',                1975, 185, 'English',  'An Irish rogue rises through 18th-century society.'),
('Paths of Glory',              1957,  88, 'English',  'A general defends soldiers charged with cowardice.'),
('Dr. Strangelove',             1964,  95, 'English',  'A general triggers a nuclear war.'),
('Lolita',                      1962, 153, 'English',  'A professor becomes obsessed with a teenager.'),
('Spartacus',                   1960, 197, 'English',  'A slave leads a revolt against Rome.'),
('Casablanca',                  1942, 102, 'English',  'A nightclub owner helps his former lover.'),
('Citizen Kane',                1941, 119, 'English',  'The life of a media tycoon is investigated.'),
('Sunset Boulevard',            1950, 110, 'English',  'A struggling screenwriter meets a faded star.'),
('All About Eve',               1950, 138, 'English',  'An ambitious actress targets a Broadway star.'),
('Singin in the Rain',          1952, 103, 'English',  'Hollywood transitions from silent films to talkies.'),
('Rear Window',                 1954, 112, 'English',  'A photographer suspects a neighbor of murder.'),
('Vertigo',                     1958, 128, 'English',  'A detective becomes obsessed with a mysterious woman.'),
('North by Northwest',          1959, 136, 'English',  'A man is mistaken for a government agent.'),
('Psycho',                      1960, 109, 'English',  'A secretary encounters a disturbed motel owner.'),
('The Birds',                   1963, 119, 'English',  'A coastal town is attacked by birds.'),
('Dial M for Murder',           1954, 105, 'English',  'A man plots to kill his wife.'),
('Rope',                        1948,  80, 'English',  'Two men hide a body at a dinner party.'),
('Rebecca',                     1940, 130, 'English',  'A woman is haunted by her husband''s first wife.'),
('Notorious',                   1946, 101, 'English',  'A spy falls for a woman used as a decoy.'),
('Strangers on a Train',        1951, 101, 'English',  'Two strangers agree to swap murders.'),
('To Catch a Thief',            1955, 106, 'English',  'A retired thief is suspected of new crimes.'),
('The Wrong Man',               1956, 105, 'English',  'A musician is falsely accused of robbery.'),
('The Man Who Knew Too Much',   1956, 120, 'English',  'A couple tries to prevent an assassination.'),
('Lawrence of Arabia',          1962, 218, 'English',  'A British officer unites Arab tribes in WWI.'),
('Ben-Hur',                     1959, 212, 'English',  'A Jewish prince is betrayed and enslaved.'),
('Gone with the Wind',          1939, 238, 'English',  'A Southern belle survives the Civil War.'),
('Wizard of Oz',                1939, 101, 'English',  'A girl is swept away to a magical land.'),
('It''s a Wonderful Life',      1946, 130, 'English',  'An angel shows a man what life would be without him.'),
('Some Like It Hot',            1959, 121, 'English',  'Two musicians disguise themselves as women.'),
('Double Indemnity',            1944, 107, 'English',  'An insurance agent helps a woman kill her husband.'),
('The Maltese Falcon',          1941, 100, 'English',  'A detective searches for a priceless statuette.'),
('On the Waterfront',           1954, 108, 'English',  'A dockworker stands up to a corrupt union.'),
('12 Angry Men',                1957,  96, 'English',  'A juror questions a murder conviction.'),
('The Bridge on the Drina',     1960, 132, 'Serbian',  'A historical epic spanning centuries.'),
('Stalker',                     1979, 162, 'Russian',  'A guide leads men through a mysterious Zone.'),
('Solaris',                     1972, 167, 'Russian',  'A psychologist investigates a space station.'),
('Andrei Rublev',               1966, 205, 'Russian',  'The life of a medieval Russian icon painter.'),
('The Mirror',                  1975, 108, 'Russian',  'Memories and dreams intertwine.'),
('Bicycle Thieves',             1948,  89, 'Italian',  'A man searches Rome for his stolen bicycle.'),
('La Dolce Vita',               1960, 174, 'Italian',  'A journalist navigates Rome''s social scene.'),
('8½',                          1963, 138, 'Italian',  'A director struggles with creative block.'),
('Rocco and His Brothers',      1960, 177, 'Italian',  'A family migrates to Milan with tragic results.'),
('The Battle of Algiers',       1966, 121, 'Italian',  'The Algerian independence movement.'),
('Breathless',                  1960,  90, 'French',   'A French gangster goes on the run.'),
('The 400 Blows',               1959,  99, 'French',   'A misunderstood boy escapes into the streets.'),
('Jules and Jim',               1962, 105, 'French',   'Two friends love the same free-spirited woman.'),
('Contempt',                    1963, 103, 'French',   'A screenwriter watches his marriage crumble.'),
('Pierrot le Fou',              1965, 110, 'French',   'A man leaves his wife for an old flame.'),
('Vivre Sa Vie',                1962,  85, 'French',   'A woman drifts into prostitution in Paris.'),
('Cleo from 5 to 7',            1962,  90, 'French',   'A singer awaits her medical diagnosis.'),
('Hiroshima Mon Amour',         1959,  90, 'French',   'A French actress and a Japanese architect.'),
('Last Year at Marienbad',      1961,  94, 'French',   'A man tries to convince a woman they met before.'),
('The Wild Child',              1970,  83, 'French',   'A doctor civilizes a feral boy.'),
('Shoah',                       1985, 566, 'French',   'An epic Holocaust documentary.'),
('Monsieur Hulot''s Holiday',   1953,  83, 'French',   'A clumsy man vacations at a seaside resort.'),
('Mon Oncle',                   1958, 116, 'French',   'A man contrasts modern and traditional life.'),
('Traffic',                     1971,  96, 'French',   'A car designer drives to an auto show.'),
('The Umbrellas of Cherbourg',  1964,  91, 'French',   'A love story told entirely in song.'),
('A Man and a Woman',           1966, 102, 'French',   'Two widowed parents fall in love.'),
('Z',                           1969, 127, 'French',   'The assassination of a Greek pacifist.'),
('The Conformist',              1970, 108, 'Italian',  'A fascist agent is ordered to kill his mentor.'),
('Investigation of a Citizen Above Suspicion', 1970, 115, 'Italian', 'A police official kills his mistress.'),
('Aguirre the Wrath of God',    1972,  93, 'German',   'A mad conquistador searches for El Dorado.'),
('Fitzcarraldo',                1982, 158, 'German',   'A dreamer hauls a ship over a mountain.'),
('Nosferatu',                   1922,  94, 'German',   'A vampire stalks a young man''s wife.'),
('Metropolis',                  1927, 153, 'German',   'Workers rebel in a futuristic city.'),
('The Cabinet of Dr Caligari',  1920,  76, 'German',   'A hypnotist uses a sleepwalker to commit murders.'),
('M',                           1931, 117, 'German',   'A child murderer is hunted by criminals.'),
('The Blue Angel',              1930, 108, 'German',   'A professor is ruined by a cabaret singer.'),
('Wings of Desire',             1987, 128, 'German',   'An angel wishes to become human in Berlin.'),
('Paris Texas',                 1984, 147, 'German',   'A man wanders out of the Texas desert.'),
('Rashomon',                    1950,  88, 'Japanese', 'Four witnesses give differing accounts of a crime.'),
('Seven Samurai',               1954, 207, 'Japanese', 'Samurai defend a village from bandits.'),
('Ikiru',                       1952, 143, 'Japanese', 'A bureaucrat faces his mortality.'),
('Yojimbo',                     1961, 110, 'Japanese', 'A samurai plays two gangs against each other.'),
('Sanjuro',                     1962,  96, 'Japanese', 'A samurai helps young officials fight corruption.'),
('High and Low',                1963, 143, 'Japanese', 'A businessman must choose between wealth and a life.'),
('The Hidden Fortress',         1958, 139, 'Japanese', 'Two peasants escort a princess through enemy territory.'),
('Ran',                         1985, 162, 'Japanese', 'An aging warlord divides his kingdom among his sons.'),
('Kagemusha',                   1980, 180, 'Japanese', 'A thief impersonates a dead warlord.'),
('Dersu Uzala',                 1975, 141, 'Japanese', 'A soldier befriends a Mongolian hunter.'),
('Akira',                       1988, 124, 'Japanese', 'A biker gang triggers a psychic catastrophe.'),
('Ghost in the Shell',          1995,  82, 'Japanese', 'A cyborg cop hunts a mysterious hacker.'),
('Princess Mononoke',           1997, 134, 'Japanese', 'A prince mediates between humans and forest gods.'),
('Howls Moving Castle',         2004, 119, 'Japanese', 'A girl is cursed to live as an old woman.'),
('My Neighbor Totoro',          1988,  86, 'Japanese', 'Two sisters befriend forest spirits.'),
('Castle in the Sky',           1986, 124, 'Japanese', 'A boy and girl search for a floating city.'),
('Nausicaa of the Valley of the Wind', 1984, 117, 'Japanese', 'A princess fights to save her world.'),
('Grave of the Fireflies',      1988,  89, 'Japanese', 'Two siblings struggle to survive in wartime Japan.'),
('Porco Rosso',                 1992,  94, 'Japanese', 'A WWI ace is cursed to look like a pig.'),
('The Wind Rises',              2013, 126, 'Japanese', 'A young man dreams of designing airplanes.'),
('When Marnie Was There',       2014, 103, 'Japanese', 'A girl befriends a mysterious girl in a mansion.'),
('Wolf Children',               2012, 117, 'Japanese', 'A woman raises her half-wolf children alone.'),
('The Girl Who Leapt Through Time', 2006, 98, 'Japanese', 'A teenager discovers she can leap through time.'),
('A Silent Voice',              2016, 130, 'Japanese', 'A bully seeks redemption from a deaf girl.'),
('In This Corner of the World', 2016, 129, 'Japanese', 'A woman copes with WWII in Hiroshima.'),
('Sword of the Stranger',       2007, 103, 'Japanese', 'A wandering swordsman protects a young boy.'),
('Paprika',                     2006,  90, 'Japanese', 'A therapist enters patients'' dreams.'),
('Perfect Blue',                1997,  81, 'Japanese', 'A pop star''s reality blurs with fantasy.'),
('Millennium Actress',          2001,  87, 'Japanese', 'A documentary filmmaker explores an actress''s life.'),
('Tokyo Godfathers',            2003,  92, 'Japanese', 'Three homeless people care for an abandoned baby.'),
('Burning',                     2018, 148, 'Korean',   'A young man suspects his new friend of a crime.'),
('The Handmaiden',              2016, 145, 'Korean',   'A con man targets a Japanese heiress.'),
('Memories of Murder',          2003, 132, 'Korean',   'Detectives investigate Korea''s first serial killings.'),
('Mother',                      2009, 129, 'Korean',   'A mother defends her son against a murder charge.'),
('A Bittersweet Life',          2005, 120, 'Korean',   'A mob enforcer turns against his boss.'),
('I Saw the Devil',             2010, 144, 'Korean',   'An agent hunts the man who killed his fiancee.'),
('The Wailing',                 2016, 156, 'Korean',   'Strange deaths plague a village after a stranger arrives.'),
('Train to Busan',              2016, 118, 'Korean',   'Passengers fight zombies on a speeding train.'),
('A Tale of Two Sisters',       2003, 115, 'Korean',   'Sisters return home to their stepmother.'),
('Joint Security Area',         2000, 110, 'Korean',   'Soldiers investigate a shooting at the DMZ.'),
('Spring Summer Fall Winter and Spring', 2003, 103, 'Korean', 'A monk''s life cycles through the seasons.'),
('Oasis',                       2002, 132, 'Korean',   'An ex-convict falls for a woman with cerebral palsy.'),
('Poetry',                      2010, 139, 'Korean',   'An elderly woman writes poetry while caring for her grandson.'),
('Pieta',                       2012, 104, 'Korean',   'A loan shark is visited by a woman claiming to be his mother.'),
('The Host',                    2006, 120, 'Korean',   'A family fights a river monster that took their daughter.'),
('Snowpiercer',                 2013, 126, 'Korean',   'Survivors of a new ice age live on a perpetual train.'),
('Okja',                        2017, 120, 'Korean',   'A girl tries to save her giant animal friend.'),
('The Map of Tiny Perfect Things', 2021, 99, 'English', 'Two teens are stuck in an infinite time loop.'),
('Palm Springs',                2020,  90, 'English',  'Two strangers are trapped in a time loop.'),
('Tenet',                       2020, 150, 'English',  'A secret agent manipulates the flow of time.'),
('The Father',                  2020,  97, 'English',  'An aging man struggles with dementia.'),
('Minari',                      2020, 115, 'Korean',   'A Korean family starts a farm in Arkansas.'),
('Nomadland',                   2020, 108, 'English',  'A woman travels the American West as a nomad.'),
('The Trial of the Chicago 7',  2020, 130, 'English',  'Seven men are tried for the 1968 Democratic Convention riots.'),
('Sound of Metal',              2020, 120, 'English',  'A drummer loses his hearing.'),
('Ma Rainey''s Black Bottom',   2020,  94, 'English',  'Tensions rise during a legendary blues singer''s recording session.'),
('Judas and the Black Messiah', 2021, 126, 'English',  'An informant infiltrates the Black Panther Party.'),
('The Power of the Dog',        2021, 126, 'English',  'A rancher torments his brother''s new wife.'),
('Drive My Car',                2021, 179, 'Japanese', 'A theater director processes grief through work.'),
('The Worst Person in the World', 2021, 128, 'Norwegian', 'A woman navigates love and identity in Oslo.'),
('Titane',                      2021, 108, 'French',   'A woman with a titanium plate in her skull commits crimes.'),
('Compartment No. 6',           2021, 107, 'Finnish',  'Two strangers share a train compartment.'),
('Petite Maman',                2021,  72, 'French',   'A girl meets a child who might be her mother.'),
('Memoria',                     2021, 136, 'Thai',     'A woman investigates a mysterious sound in her head.'),
('Dune',                        2021, 155, 'English',  'A noble family controls a desert planet.'),
('The Batman',                  2022, 176, 'English',  'Batman investigates corruption in Gotham.'),
('Everything Everywhere All at Once', 2022, 139, 'English', 'A woman explores parallel universes.'),
('The Banshees of Inisherin',   2022, 114, 'English',  'A man''s friendship is abruptly ended by his friend.'),
('Tar',                         2022, 158, 'English',  'A renowned conductor faces a reckoning.'),
('All Quiet on the Western Front', 2022, 148, 'German', 'A young German soldier experiences WWI.'),
('Decision to Leave',           2022, 138, 'Korean',   'A detective becomes obsessed with a murder suspect.'),
('Aftersun',                    2022, 102, 'English',  'A daughter reflects on a holiday with her father.'),
('The Fabelmans',               2022, 151, 'English',  'A young man discovers a truth about his family through filmmaking.'),
('Women Talking',               2022, 104, 'English',  'Women in an isolated colony deliberate their future.'),
('Oppenheimer',                 2023, 180, 'English',  'The story of the atomic bomb''s creation.'),
('Barbie',                      2023, 114, 'English',  'Barbie goes on a journey of self-discovery.'),
('Past Lives',                  2023, 106, 'English',  'Childhood sweethearts reconnect years later.'),
('Killers of the Flower Moon',  2023, 206, 'English',  'FBI investigates murders of Osage Nation members.'),
('Anatomy of a Fall',           2023, 152, 'French',   'A woman is suspected of murdering her husband.'),
('The Zone of Interest',        2023, 105, 'German',   'A Nazi commandant''s family lives beside Auschwitz.'),
('Poor Things',                 2023, 141, 'English',  'A woman brought back to life explores the world.'),
('Saltburn',                    2023, 131, 'English',  'A student becomes obsessed with his classmate''s family.'),
('Society of the Snow',         2023, 144, 'Spanish',  'Survivors of a plane crash in the Andes.'),
('Monster',                     2023, 126, 'Japanese', 'A disaster seen from multiple perspectives.'),
('The Holdovers',               2023, 133, 'English',  'A teacher and student bond over the holidays.'),
('May December',                2023, 117, 'English',  'An actress researches a woman whose past is controversial.'),
('Priscilla',                   2023, 113, 'English',  'The story of Elvis Presley''s wife.'),
('American Fiction',            2023, 117, 'English',  'A frustrated novelist accidentally writes a bestseller.'),
('Ferrari',                     2023, 130, 'English',  'Enzo Ferrari''s turbulent 1957 season.'),
('The Substance',               2024, 140, 'English',  'A woman uses a substance to create a perfect version of herself.'),
('Conclave',                    2024, 120, 'English',  'Cardinals gather to elect a new pope.'),
('The Brutalist',               2024, 215, 'English',  'A Hungarian architect rebuilds his life in America.'),
('Emilia Perez',                2024, 130, 'French',   'A cartel boss undergoes a transformation.'),
('Anora',                       2024, 139, 'English',  'A young woman marries the son of a Russian oligarch.'),
('Nosferatu Remake',            2024, 132, 'English',  'A reimagining of the classic vampire tale.'),
('A Real Pain',                 2024,  89, 'English',  'Two cousins travel to Poland to honor their grandmother.'),
('Nickel Boys',                 2024, 140, 'English',  'Two boys survive a brutal reform school in 1960s Florida.'),
('I Saw the TV Glow',           2024, 100, 'English',  'Two teenagers bond over a mysterious TV show.'),
('Civil War',                   2024, 109, 'English',  'Journalists travel through a war-torn America.'),
('Alien: Romulus',              2024, 119, 'English',  'Young colonists face a terrifying encounter in space.'),
('Kingdom of the Planet of the Apes', 2024, 145, 'English', 'A new ape leader builds an empire.'),
('Furiosa',                     2024, 148, 'English',  'The origin story of Furiosa in the wasteland.'),
('Dune Part Two',               2024, 167, 'English',  'Paul Atreides unites with the Fremen against the Harkonnens.'),
('Inside Out 2',                2024, 100, 'English',  'New emotions emerge in a teenager''s mind.'),
('Deadpool and Wolverine',      2024, 128, 'English',  'Two mutants are forced on a dangerous mission.'),
('Alien',                       1979, 117, 'English',  'The crew of a spaceship encounters a deadly alien.'),
('Aliens',                      1986, 137, 'English',  'Marines battle a colony of aliens.'),
('The Terminator',              1984, 107, 'English',  'A cyborg is sent back in time to kill a woman.'),
('Terminator 2 Judgment Day',   1991, 137, 'English',  'A reprogrammed Terminator protects a boy.'),
('RoboCop',                     1987, 102, 'English',  'A murdered cop is revived as a cyborg policeman.'),
('Total Recall',                1990, 113, 'English',  'A man discovers his memories are implanted.'),
('Basic Instinct',              1992, 127, 'English',  'A detective investigates a seductive suspect.'),
('Speed',                       1994,  94, 'English',  'A bus must stay above 50 mph or explode.'),
('Point Break',                 1991, 122, 'English',  'An FBI agent infiltrates a gang of surfer bank robbers.'),
('Con Air',                     1997, 115, 'English',  'A parolee must stop convicts who hijack his flight.'),
('Face Off',                    1997, 138, 'English',  'A cop and criminal literally swap faces.'),
('The Rock',                    1996, 136, 'English',  'Terrorists seize Alcatraz and threaten San Francisco.'),
('Armageddon',                  1998, 151, 'English',  'Drillers are sent to destroy an asteroid.'),
('Independence Day',            1996, 145, 'English',  'Aliens invade Earth on July 4th.'),
('Men in Black',                1997,  98, 'English',  'Agents police alien activity on Earth.'),
('The Truman Show',             1998, 103, 'English',  'A man discovers his life is a TV show.'),
('Pleasantville',               1998, 124, 'English',  'Siblings are transported into a 1950s TV show.'),
('American Beauty',             1999, 122, 'English',  'A suburban man has a midlife crisis.'),
('American History X',          1998, 119, 'English',  'A reformed neo-Nazi tries to help his brother.'),
('The Sixth Sense',             1999, 107, 'English',  'A boy who sees dead people seeks help from a psychologist.'),
('Unbreakable',                 2000, 106, 'English',  'A man discovers he may be a superhero.'),
('Signs',                       2002, 106, 'English',  'A family discovers crop circles on their farm.'),
('The Village',                 2004, 108, 'English',  'A 19th-century village is surrounded by frightening creatures.'),
('Split',                       2016, 117, 'English',  'Three girls are kidnapped by a man with 24 personalities.'),
('Glass',                       2019, 129, 'English',  'Three men with extraordinary abilities clash.'),
('Old',                         2021, 108, 'English',  'A family vacations on a beach that rapidly ages them.'),
('Knock at the Cabin',          2023, 100, 'English',  'Strangers break into a family''s cabin with a dire ultimatum.'),
('Shutter Island',              2010, 138, 'English',  'A US Marshal investigates a mental institution.'),
('Cape Fear',                   1991, 128, 'English',  'A lawyer is stalked by a man he once defended.'),
('The Fugitive',                1993, 130, 'English',  'A man hunts the one-armed man who killed his wife.'),
('Air Force One',               1997, 124, 'English',  'The president fights back against hijackers.'),
('The Negotiator',              1998, 139, 'English',  'A hostage negotiator takes hostages himself.'),
('Collateral',                  2004, 120, 'English',  'A cab driver is taken hostage by a hitman.'),
('Michael Clayton',             2007, 119, 'English',  'A fixer uncovers corporate malfeasance.'),
('Syriana',                     2005, 128, 'English',  'The global politics of the oil industry.'),
('Babel',                       2006, 143, 'English',  'Interconnected stories across four countries.'),
('Crash',                       2004, 112, 'English',  'Racial tensions collide in Los Angeles.'),
('Million Dollar Baby',         2004, 132, 'English',  'A trainer helps a determined woman become a boxer.'),
('Mystic River',                2003, 138, 'English',  'Three childhood friends are reunited by tragedy.'),
('Blood Diamond',               2006, 143, 'English',  'A smuggler and a fisherman search for a rare diamond.'),
('The Last King of Scotland',   2006, 123, 'English',  'A doctor becomes Idi Amin''s personal physician.'),
('Hotel Rwanda',                2004, 122, 'English',  'A hotel manager shelters Tutsi refugees during the genocide.'),
('Sophie''s Choice',            1982, 150, 'English',  'A Holocaust survivor faces an unimaginable choice.'),
('The Pianist',                 2002, 150, 'English',  'A Polish pianist survives the Holocaust.'),
('Son of Saul',                 2015, 107, 'Hungarian','A Sonderkommando tries to give a boy a proper burial.'),
('Ida',                         2013,  82, 'Polish',   'A novice nun discovers her Jewish past.'),
('Cold War',                    2018,  88, 'Polish',   'A love story across Cold War Europe.'),
('Katyn',                       2007, 122, 'Polish',   'The aftermath of the Katyn massacre.'),
('A Separation',                2011, 123, 'Persian',  'A couple''s separation has wide-reaching consequences.'),
('The Salesman',                2016, 125, 'Persian',  'A couple is affected by an incident in their new home.'),
('About Elly',                  2009, 119, 'Persian',  'A woman disappears during a weekend trip.'),
('Capernaum',                   2018, 126, 'Arabic',   'A boy sues his parents for giving him life.'),
('The Square',                  2017, 151, 'Swedish',  'An art curator faces a public relations crisis.'),
('Force Majeure',               2014, 120, 'Swedish',  'A man''s cowardice during an avalanche has consequences.'),
('The Hunt',                    2012, 115, 'Danish',   'A teacher is falsely accused of child abuse.'),
('Melancholia',                 2011, 136, 'Danish',   'Two sisters cope as a rogue planet approaches Earth.'),
('Dancer in the Dark',          2000, 140, 'Danish',   'A factory worker faces a tragic destiny.'),
('Breaking the Waves',          1996, 159, 'Danish',   'A woman sacrifices herself for her paralyzed husband.'),
('The Celebration',             1998, 105, 'Danish',   'A family''s secrets emerge at a birthday dinner.'),
('Let the Right One In',        2008, 115, 'Swedish',  'A bullied boy befriends a vampire.'),
('The Girl with the Dragon Tattoo', 2009, 152, 'Swedish', 'A journalist and hacker investigate a disappearance.'),
('Wild Strawberries',           1957,  91, 'Swedish',  'An elderly professor reflects on his life.'),
('The Seventh Seal',            1957,  96, 'Swedish',  'A knight plays chess with Death.'),
('Persona',                     1966,  83, 'Swedish',  'A nurse cares for a silent actress.'),
('Scenes from a Marriage',      1974, 168, 'Swedish',  'A couple''s marriage gradually dissolves.'),
('Fanny and Alexander',         1982, 188, 'Swedish',  'A Swedish family''s life over three decades.'),
('The Emigrants',               1971, 191, 'Swedish',  'Swedish families emigrate to America.'),
('Hour of the Wolf',            1968,  90, 'Swedish',  'An artist is haunted by demons on an island.'),
('Through a Glass Darkly',      1961,  89, 'Swedish',  'A woman''s schizophrenia tears a family apart.'),
('Amarcord',                    1973, 123, 'Italian',  'Memories of a small Italian town in the 1930s.'),
('Satyricon',                   1969, 138, 'Italian',  'Two young men seek pleasure in ancient Rome.'),
('The Leopard',                 1963, 186, 'Italian',  'A Sicilian aristocrat navigates social change.'),
('Salo',                        1975, 117, 'Italian',  'Fascists subject teenagers to extreme depravity.'),
('The Gospel According to St Matthew', 1964, 137, 'Italian', 'The life of Jesus told in a realist style.'),
('Teorema',                     1968,  98, 'Italian',  'A mysterious stranger disrupts a bourgeois family.'),
('Accattone',                   1961, 120, 'Italian',  'A pimp struggles to survive on the streets of Rome.'),
('Red Desert',                  1964, 120, 'Italian',  'A woman struggles with alienation in industrial Italy.'),
('Blow-Up',                     1966, 111, 'English',  'A photographer discovers evidence of murder in a photo.'),
('The Passenger',               1975, 126, 'English',  'A journalist assumes a dead man''s identity.'),
('Zabriskie Point',             1970, 112, 'English',  'Two young Americans escape to the desert.'),
('Once Upon a Time in America', 1984, 229, 'English',  'The lives of Jewish gangsters in New York.'),
('Stagecoach',                  1939,  96, 'English',  'Disparate passengers travel through Apache territory.'),
('High Noon',                   1952,  85, 'English',  'A marshal faces outlaws alone on his wedding day.'),
('Shane',                       1953, 118, 'English',  'A retired gunslinger helps a farming family.'),
('The Searchers',               1956, 119, 'English',  'A Civil War veteran searches years for his niece.'),
('Rio Bravo',                   1959, 141, 'English',  'A sheriff and his allies hold a killer in jail.'),
('True Grit',                   1969, 128, 'English',  'A young girl hires a marshal to avenge her father.'),
('The Wild Bunch',              1969, 145, 'English',  'Aging outlaws plan one last heist in Mexico.'),
('Butch Cassidy and the Sundance Kid', 1969, 110, 'English', 'Two outlaws flee to Bolivia.'),
('McCabe and Mrs Miller',       1971, 121, 'English',  'A gambler and prostitute build a frontier town.'),
('Pat Garrett and Billy the Kid', 1973, 106, 'English', 'A lawman hunts his old friend.'),
('Unforgiven',                  1992, 131, 'English',  'A retired outlaw takes one last job.');
-----внесување во табелата Movie со вештачки филмови
INSERT INTO Movie (title, release_year, duration, language, description)
SELECT

    (
        arr1[1 + floor(random() * array_length(arr1, 1))::int]
        || ' ' ||
        arr2[1 + floor(random() * array_length(arr2, 1))::int]
        ||
        CASE WHEN random() < 0.4 THEN
            ' ' || arr3[1 + floor(random() * array_length(arr3, 1))::int]
        ELSE '' END
    ) AS title,

    1970 + (random() * 55)::INT,

    75 + (random() * 120)::INT,

    arr4[1 + floor(random() * array_length(arr4, 1))::int],

    arr5[1 + floor(random() * array_length(arr5, 1))::int]

FROM generate_series(1, 4500),

LATERAL (
    SELECT
        ARRAY[
            'The','A','Last','Dark','Silent','Lost','Broken','Shadow','Blood','Iron',
            'Golden','Crimson','Hollow','Forgotten','Hidden','Eternal','Fallen','Rising',
            'Black','White','Red','Cold','Dead','Final','Secret','Burning','Frozen',
            'Shattered','Twisted','Pale','Distant','Empty','Fading','Burning','Sacred',
            'Haunted','Stolen','Naked','Savage','Ancient','Electric','Neon','Glass',
            'Stone','Steel','Silver','Wild','Quiet','Loud','Bitter','Sweet'
        ] AS arr1,

        ARRAY[
            'Knight','Storm','Garden','River','Mirror','Road','Sky','Wolf','Star','Moon',
            'Sun','Fire','Rain','Wind','Ocean','Mountain','Forest','Desert','City','Island',
            'Night','Dawn','Dusk','Dream','Shadow','Echo','Flame','Tide','Ghost','King',
            'Queen','Prince','Warrior','Hunter','Stranger','Child','Angel','Demon','Beast',
            'Tiger','Dragon','Phoenix','Falcon','Raven','Serpent','Crow','Fox','Bear','Lion',
            'Horizon','Abyss','Void','Silence','Memory','Promise','Lie','Truth','War','Peace',
            'Love','Hate','Hope','Fear','Fate','Soul','Heart','Mind','Blood','Bone',
            'Bridge','Tower','Gate','Wall','Path','Trail','Shore','Cliff','Valley','Peak',
            'Throne','Crown','Sword','Shield','Arrow','Chain','Key','Door','Window','Room',
            'House','Street','District','Empire','Kingdom','Republic','Nation','World','Realm'
        ] AS arr2,

        ARRAY[
            'of Destiny','of Shadows','of Silence','of Fire','of Ice','of Steel',
            'of Lies','of Hope','of Sorrow','of War','of the Lost','of the Fallen',
            'of the Dead','of the Brave','of the Damned','of the Ages','Rising',
            'Reborn','Unleashed','Forsaken','Betrayed','Redeemed','Unbroken',
            'Forever','Never Again','Once More','Part II','Returns','Begins',
            'Strikes Back','Awakens','Endures','Survives','Prevails','Falls'
        ] AS arr3,

        ARRAY[
            'English','English','English','English','English',
            'Spanish','French','German','Italian','Japanese',
            'Korean','Chinese','Hindi','Macedonian','Portuguese',
            'Russian','Turkish','Arabic','Swedish','Danish'
        ] AS arr4,

        ARRAY[
            'An epic tale of survival and redemption.',
            'A gripping story of love and betrayal.',
            'Two rivals face each other in a final showdown.',
            'A journey through darkness toward the light.',
            'Secrets buried for decades come to light.',
            'A family torn apart must find their way back.',
            'One man stands between order and chaos.',
            'The truth is more terrifying than fiction.',
            'When the past catches up, nothing is safe.',
            'A story of courage in the face of impossible odds.',
            'Love and duty collide in an unforgiving world.',
            'The line between good and evil blurs.',
            'A new threat emerges from the shadows.',
            'Heroes are forged in the fires of adversity.',
            'Nothing is as it seems in this twisted tale.',
            'A race against time to prevent catastrophe.',
            'The hunt begins and no one is safe.',
            'Loyalties are tested when everything falls apart.',
            'An unlikely hero rises to meet their destiny.',
            'The world will never be the same again.'
        ] AS arr5
) t;
-----внесување во табелата Genre_Movie
INSERT INTO Genre_Movie (genre_id, movie_id)
SELECT DISTINCT
    1 + (random() * 19)::INT,
    m
FROM generate_series(1, 4893) m,
     generate_series(1, 3)
ON CONFLICT DO NOTHING;


-----внесување во табелата Cinema
INSERT INTO Cinema (name, city, address, phone, email)
SELECT
    'CinemaHouse ' || gs,
    (ARRAY['Skopje','Bitola','Ohrid','Tetovo','Veles',
           'Strumica','Kumanovo','Stip','Kocani','Gostivar'])[1 + (random()*9)::INT],
    'Street ' || gs || ', No ' || (1 + (random()*200)::INT),
    '+3897' || LPAD((1000000 + (random()*8999999)::INT)::TEXT, 7, '0'),
    'cinema' || gs || '@example.com'
FROM generate_series(1, 50) gs;


-----внесување во табелата Hall
INSERT INTO Hall (cinema_id, name, capacity)
SELECT
    c,
    'Hall ' || h,
    200
FROM generate_series(1, 50) c,
     generate_series(1, 4)  h;

-----внесување во табелата Seat_Type
INSERT INTO Seat_Type (type, price)
VALUES
    ('Standard',  300),
    ('VIP',       700),
    ('Recliner',  500),
    ('Couple',    600),
    ('Disabled',  200);

-----внесување во табелата Seat

INSERT INTO Seat (hall_id, seat_type_id, seat_row, seat_number)
SELECT
    h,
    1 + (random() * 4)::INT,
    row_n,
    seat_n
FROM generate_series(1, 200) h,
     generate_series(1, 20)  row_n,
     generate_series(1, 10)  seat_n;


-----внесување во табелата CinemaUser
WITH data AS (
    SELECT
        gs,
        CASE WHEN random() < 0.5 THEN 'F' ELSE 'M' END AS gender,

        ARRAY[
            'Ana','Marija','Elena','Sara','Maja','Lena','Tanja','Sanja','Milena','Irena',
            'Kristina','Vesna','Natasa','Lidija','Gordana','Sonja','Biljana','Silvija','Daniela','Valentina',
            'Emma','Olivia','Sophia','Isabella','Mia','Charlotte','Amelia','Harper','Evelyn','Abigail'
        ] AS female_names,

        ARRAY[
            'Ivan','Nikola','Petar','Viktor','Darko','Boris','Goran','Zoran','Stefan','Dimitar',
            'James','John','Robert','Michael','William','David','Richard','Joseph','Thomas','Charles'
        ] AS male_names,

        ARRAY[
            'Stojanovska','Petrova','Nikolova','Ilieva','Popova','Kostova','Lazarova','Todorova',
            'Smith','Johnson','Williams','Brown','Jones','Miller','Davis','Wilson','Anderson'
        ] AS female_surnames,

        ARRAY[
            'Stojanovski','Petrov','Nikolov','Iliev','Popov','Kostov','Lazarov','Todorov',
            'Smith','Johnson','Williams','Brown','Jones','Miller','Davis','Wilson','Anderson'
        ] AS male_surnames
    FROM generate_series(1, 100000) gs
),

picked AS (
    SELECT
        gs,
        gender,

        CASE WHEN gender = 'F'
            THEN female_names[ceil(random()*array_length(female_names,1))::int]
            ELSE male_names[ceil(random()*array_length(male_names,1))::int]
        END AS first_name,

        CASE WHEN gender = 'F'
            THEN female_surnames[ceil(random()*array_length(female_surnames,1))::int]
            ELSE male_surnames[ceil(random()*array_length(male_surnames,1))::int]
        END AS last_name

    FROM data
)

INSERT INTO CinemaUser (first_name, last_name, email, phone, registration_date)
SELECT
    first_name,
    last_name,

    LOWER(first_name) || '_' || LOWER(last_name) || '_' || gs::TEXT || '@mail.com',

    '+3897' || LPAD((1000000 + (random()*8999999)::INT)::TEXT, 7, '0'),
    DATE '2000-01-01' + (random() * 5000)::INT   -- 2000–2013 pred rezervacii
FROM picked;

-----внесување во табелата Role
INSERT INTO Role (role_name, description, base_salary)
VALUES
    ('Manager',       'Cinema manager',          60000),
    ('Cashier',       'Ticket sales',            25000),
    ('Projectionist', 'Movie projection',        30000),
    ('Security',      'Security guard',          22000),
    ('Cleaner',       'Cleaning staff',          18000),
    ('Technician',    'Equipment maintenance',   35000),
    ('Bartender',     'Bar service',             24000),
    ('Supervisor',    'Floor supervisor',        40000),
    ('Marketing',     'Marketing specialist',    38000),
    ('Accountant',    'Financial accounting',    45000);


-----внесување во табелата Employee
WITH data AS (
    SELECT
        gs,
        c,
        e,
        CASE WHEN random() < 0.5 THEN 'F' ELSE 'M' END AS gender,

        ARRAY[
            'Ana','Marija','Elena','Sara','Maja','Lena','Tanja','Sanja','Milena','Irena',
            'Kristina','Vesna','Natasa','Lidija','Gordana','Sonja','Biljana','Silvija','Daniela','Valentina',
            'Emma','Olivia','Sophia','Isabella','Mia','Charlotte','Amelia','Harper','Evelyn','Abigail'
        ] AS female_names,

        ARRAY[
            'Ivan','Nikola','Petar','Viktor','Darko','Boris','Goran','Zoran','Stefan','Dimitar',
            'James','John','Robert','Michael','William','David','Richard','Joseph','Thomas','Charles'
        ] AS male_names,

        ARRAY[
            'Stojanovska','Petrova','Nikolova','Ilieva','Popova','Kostova','Lazarova','Todorova',
            'Smith','Johnson','Williams','Brown','Jones','Miller','Davis','Wilson','Anderson'
        ] AS female_surnames,

        ARRAY[
            'Stojanovski','Petrov','Nikolov','Iliev','Popov','Kostov','Lazarov','Todorov',
            'Smith','Johnson','Williams','Brown','Jones','Miller','Davis','Wilson','Anderson'
        ] AS male_surnames

    FROM generate_series(1, 50) c,
         generate_series(1, 10) e,
         generate_series(1, 1) gs
),

picked AS (
    SELECT
        c,
        e,
        gender,

        CASE WHEN gender = 'F' THEN
            (SELECT x FROM unnest(female_names) x ORDER BY random() LIMIT 1)
        ELSE
            (SELECT x FROM unnest(male_names) x ORDER BY random() LIMIT 1)
        END AS first_name,

        CASE WHEN gender = 'F' THEN
            (SELECT x FROM unnest(female_surnames) x ORDER BY random() LIMIT 1)
        ELSE
            (SELECT x FROM unnest(male_surnames) x ORDER BY random() LIMIT 1)
        END AS last_name

    FROM data
)
INSERT INTO Employee (cinema_id, first_name, last_name, phone, email, hire_date)
SELECT
    c,

    first_name,
    last_name,

    '+3897' || LPAD((1000000 + (random()*8999999)::INT)::TEXT, 7, '0'),

    LOWER(first_name) || '_' || LOWER(last_name) || '_' ||
    (c * 10 + e)::TEXT || '@gmail.com',

    DATE '1995-01-01' + (random() * 3650)::INT  -- 1995–2005, пред резервациите

FROM picked;


-----внесување во табелата Employee_Role
INSERT INTO Employee_Role (employee_id, role_id)
SELECT
    gs,
    1 + (random() * 9)::INT
FROM generate_series(1, 500) gs
ON CONFLICT DO NOTHING;

-----внесување во табелата Salary
INSERT INTO Salary (employee_id, amount, payment_date)
SELECT
    er.employee_id,
    (r.base_salary * (0.9 + random() * 0.2))::INT AS amount,  -- base_salary ±10%
    DATE '2000-01-01' + (random() * 9130)::INT AS payment_date
FROM (
    SELECT employee_id, role_id,
           row_number() OVER (ORDER BY random()) AS rn
    FROM Employee_Role
) er
JOIN Role r ON r.role_id = er.role_id
CROSS JOIN generate_series(1, 200) gs
WHERE er.rn <= 500
ORDER BY random()
LIMIT 100000;

-----внесување во табелата PresentationRights
INSERT INTO PresentationRights (movie_id, cinema_id, start_date, end_date)
SELECT DISTINCT
    1 + (random() * 4892)::INT,
    1 + (random() *   49)::INT,
    LEAST(d1, d2)       AS start_date,
    GREATEST(d1, d2)    AS end_date
FROM (
    SELECT
        DATE '2000-01-01' + (random() * 9130)::INT AS d1,
        DATE '2000-01-01' + (random() * 9130)::INT AS d2
    FROM generate_series(1, 15000)
) dates
ON CONFLICT DO NOTHING;

-----внесување во табелата Showtime
INSERT INTO Showtime (movie_id, hall_id, start_time, end_time, base_price)
WITH
slots AS (
    SELECT
        h.hall_id,
        (DATE '2000-01-01' + ((gs - 1) || ' days')::INTERVAL)::DATE  AS show_date,

        (ARRAY[10,12,14,16,18,20])[1 + (random() * 5)::INT] AS start_hour
    FROM generate_series(1, 9000) gs
    CROSS JOIN Hall h
),
slots_with_movie AS (
    SELECT
        s.hall_id,
        s.show_date,
        s.start_hour,
        1 + (floor(random() * 5000)::INT) AS movie_id
    FROM slots s
)
SELECT
    swm.movie_id,
    swm.hall_id,
    (swm.show_date::TIMESTAMP + (swm.start_hour || ' hours')::INTERVAL) AS start_time,
    (swm.show_date::TIMESTAMP + (swm.start_hour || ' hours')::INTERVAL
        + (m.duration * INTERVAL '1 minute')) AS end_time,
    200 + (random() * 600)::INT AS base_price
FROM slots_with_movie swm
JOIN Movie m ON m.movie_id = swm.movie_id;


-----внесување во табелата Expense
INSERT INTO Expense (cinema_id, description, amount, expense_date)
SELECT
    1 + (random() * 49)::INT,   -- cinema_id: 1–50
    (ARRAY['Rent','Utilities','Maintenance','Marketing','Supplies',
           'Equipment','Cleaning','Security','IT','Insurance'])[1+(random()*9)::INT],
    5000 + (random() * 100000)::INT,
    DATE '2000-01-01' + (random() * 9130)::INT
FROM generate_series(1, 50000) gs;


-----внесување во табелата Supplier
INSERT INTO Supplier (name, phone, email, address)
SELECT
    'Supplier ' || gs,
    '+38970' || LPAD((1000000 + (random()*8999999)::INT)::TEXT, 7, '0'),
    'supplier' || gs || '@biz.com',
    'Industrial Zone ' || gs
FROM generate_series(1, 100) gs;

-----внесување во табелата Product
INSERT INTO Product (name, price, stock_quantity)
SELECT
    (ARRAY['Popcorn Large','Popcorn Medium','Cola 0.5L','Cola 1L','Water',
           'Nachos','Hot Dog','Coffee','Tea','Juice',
           'Candy Box','Ice Cream','Chips','Pretzel','Sandwich',
           'Beer','Wine','Cocktail','Milkshake','Energy Drink'])[1+(random()*19)::INT]
        || ' #' || gs,
    50  + (random() * 450)::INT,
    100 + (random() * 9900)::INT
FROM generate_series(1, 200) gs;


-----внесување во табелата Supply
INSERT INTO Supply (product_id, supplier_id, expense_id, quantity, supply_date, price_per_unit)
WITH supply_base AS (
    SELECT
        (1 + (random() * 199)::INT) AS product_id,
        (1 + (random() *  99)::INT) AS supplier_id,
        e.expense_id,
        10  + (random() * 990)::INT AS quantity,
        DATE '2000-01-01' + (random() * 9130)::INT  AS supply_date,
        20  + (random() * 300)::INT AS price_per_unit,
        row_number() OVER (ORDER BY random()) AS rn
    FROM Expense e
)
SELECT product_id, supplier_id, expense_id, quantity, supply_date, price_per_unit
FROM supply_base
WHERE rn <= 5000;

-----внесување во табелата Reservation
DO $$
DECLARE
    batch_size INT := 500000;
    total      INT := 10000000;
    i          INT := 0;
BEGIN
    WHILE i < total LOOP
        INSERT INTO Reservation (user_id, showtime_id, employee_id, reservation_date, status)
        WITH one_employee_per_showtime AS (
            SELECT DISTINCT ON (st.showtime_id)
                st.showtime_id,
                st.start_time,
                e.employee_id
            FROM Showtime  st
            JOIN Hall      h  ON h.hall_id   = st.hall_id
            JOIN Employee  e  ON e.cinema_id = h.cinema_id
            ORDER BY st.showtime_id, random()
        ),
        sampled AS (
            SELECT
                showtime_id,
                start_time,
                employee_id,
                row_number() OVER (ORDER BY random()) AS rn
            FROM one_employee_per_showtime
        )
        SELECT
            1 + (random() * 99999)::INT  AS user_id,
            s.showtime_id,
            s.employee_id,
            (s.start_time::DATE - (1 + (random() * 29)::INT))  AS reservation_date,
            (ARRAY['PENDING','CONFIRMED','CANCELLED']::statusReservation[])[1+(random()*2)::INT] AS status
        FROM sampled s
        WHERE s.rn <= batch_size
        ON CONFLICT DO NOTHING;

        i := i + batch_size;
        RAISE NOTICE 'Reservation inserted: % / %', i, total;
    END LOOP;
END;
$$;


-----внесување во табелата Ticket
DO $$
DECLARE
    batch_size INT := 100000;
    total      INT := 15000000;
    i          INT := 0;
    inserted   INT := 0;
    offset_val INT := 0;
BEGIN
    WHILE i < total LOOP
        INSERT INTO Ticket (showtime_id, seat_id, reservation_id, price, purchase_date)
        WITH chosen_showtimes AS (
            SELECT
                st.showtime_id,
                st.hall_id,
                st.base_price,
                st.start_time,
                h.capacity
            FROM Showtime st
            JOIN Hall h ON h.hall_id = st.hall_id
            ORDER BY st.showtime_id
            LIMIT batch_size OFFSET offset_val
        ),
        res_per_showtime AS (
            SELECT
                r.reservation_id,
                r.showtime_id,
                cs.hall_id,
                cs.capacity,
                cs.base_price,
                cs.start_time,
                row_number() OVER (PARTITION BY r.showtime_id ORDER BY r.reservation_id) AS seat_rank
            FROM chosen_showtimes cs
            JOIN Reservation r ON r.showtime_id = cs.showtime_id
        ),
        capped_res AS (
            SELECT reservation_id, showtime_id, hall_id, seat_rank, base_price, start_time
            FROM res_per_showtime
            WHERE seat_rank <= capacity
        ),
        seats_ranked AS (
            SELECT
                s.seat_id,
                s.hall_id,
                s.seat_type_id,
                row_number() OVER (PARTITION BY s.hall_id ORDER BY s.seat_id) AS seat_rn
            FROM Seat s
        ),
        final_assignment AS (
            SELECT
                cr.reservation_id,
                cr.showtime_id,
                sr.seat_id,
                sr.seat_type_id,
                cr.base_price,
                cr.start_time
            FROM capped_res cr
            JOIN seats_ranked sr
                ON sr.hall_id = cr.hall_id
               AND sr.seat_rn = cr.seat_rank
        )
        SELECT
            fa.showtime_id,
            fa.seat_id,
            fa.reservation_id,
            (fa.base_price * CASE fa.seat_type_id
                WHEN 1 THEN 1.0
                WHEN 2 THEN 2.0
                WHEN 3 THEN 1.5
                WHEN 4 THEN 1.8
                WHEN 5 THEN 0.7
                ELSE 1.0
            END)::INT AS price,
            (fa.start_time::DATE - (1 + (random() * 29)::INT)) AS purchase_date
        FROM final_assignment fa;

        GET DIAGNOSTICS inserted = ROW_COUNT;
        i := i + inserted;
        offset_val := offset_val + batch_size;

        IF offset_val >= 1800000 THEN
            offset_val := 0;
        END IF;

        RAISE NOTICE 'Ticket inserted so far: %', i;
    END LOOP;
    RAISE NOTICE 'Total tickets inserted: %', i;
END;
$$;

-----внесување во табелата Review
DO $$
DECLARE
    batch_size  INT := 500000;
    total       INT := 15000000;
    i           INT := 0;
BEGIN
    WHILE i < total LOOP
        INSERT INTO Review (user_id, movie_id, rating, comment, review_date)
        SELECT
            1 + (random() *  99999)::INT,   -- user_id: 1–100000
            1 + (random() *   4892)::INT,   -- movie_id: 1–5000 (сите филми)
            1 + (random() *      9)::INT,
            (ARRAY['Great!','Loved it','Boring','Amazing','Not bad',
                   'Terrible','Must watch','Waste of time','Brilliant','Average'])[1+(random()*9)::INT],
            DATE '2000-01-01' + (random() * 8765)::INT
        FROM generate_series(1, batch_size);
        i := i + batch_size;
        RAISE NOTICE 'Review inserted: % / %', i, total;
    END LOOP;
END;
$$;

-----внесување во табелата ReservationPayment
DO $$
DECLARE
    batch_size INT := 500000;
    total      INT := 10000000;
    i          INT := 0;
BEGIN
    WHILE i < total LOOP
        INSERT INTO ReservationPayment
            (user_id, reservation_id, employee_id, amount, payment_date, payment_method)
        WITH

        ticket_totals AS (

            SELECT
                t.reservation_id,
                SUM(t.price) AS total_ticket_price
            FROM Ticket t
            WHERE t.reservation_id > i
              AND t.reservation_id <= i + batch_size
            GROUP BY t.reservation_id
        ),

        batch AS (
            SELECT DISTINCT ON (r.reservation_id)
                r.reservation_id,
                r.user_id,
                r.reservation_date,
                e.employee_id,
                tt.total_ticket_price AS amount
            FROM ticket_totals tt
            JOIN Reservation r  ON r.reservation_id = tt.reservation_id
            JOIN Showtime    st ON st.showtime_id   = r.showtime_id
            JOIN Hall        h  ON h.hall_id        = st.hall_id
            JOIN Employee    e  ON e.cinema_id      = h.cinema_id
            ORDER BY r.reservation_id, random()
        )

        SELECT
            user_id,
            reservation_id,
            employee_id,
            amount,
            reservation_date + (random() * 3)::INT   AS payment_date,
            (ARRAY['Cash','Credit Card','Debit Card','Online','Voucher'])
                [1+(random()*4)::INT]              AS payment_method
        FROM batch;

        i := i + batch_size;
        RAISE NOTICE 'ReservationPayment inserted: % / %', i, total;
    END LOOP;
END;
$$;

-----внесување во табелата CinemaOrder
INSERT  INTO CinemaOrder (user_id, employee_id, order_date, total_price, status)
WITH order_base AS (
    SELECT
        1 + (random() * 99999)::INT              AS user_id,
        e.employee_id,
        row_number() OVER (ORDER BY random())    AS rn
    FROM Employee e
    CROSS JOIN generate_series(1, 3000) gs
)
SELECT
    user_id,
    employee_id,
    DATE '2000-01-01' + (random() * 8765)::INT  AS order_date,
    0                                            AS total_price,  -- ќе се UPDATE-ира подоцна
    (ARRAY['PREPARING','COMPLETED']::statusOrder[])[1+(random()*1)::INT] AS status
FROM order_base
WHERE rn <= 1500000;

INSERT INTO Order_Product (order_id, product_id, quantity, price_at_order)
SELECT
    gs                  AS order_id,
    1 + (random() * 199)::INT    AS product_id,
    1 + (random() *   5)::INT     AS quantity,
    50 + (random() * 500)::INT      AS price_at_order
FROM generate_series(1, 1500000) gs;

-----внесување во табелата Order_Product
INSERT INTO Order_Product (order_id, product_id, quantity, price_at_order)
SELECT
    1 + (random() * 1499999)::INT   AS order_id,
    1 + (random() *    199)::INT    AS product_id,
    1 + (random() *      5)::INT   AS quantity,
    50 + (random() *    500)::INT   AS price_at_order
FROM generate_series(1, 3000000) gs;


UPDATE CinemaOrder co
SET total_price = sub.real_total
FROM (
    SELECT order_id, SUM(quantity * price_at_order) AS real_total
    FROM Order_Product
    GROUP BY order_id
) sub
WHERE co.order_id = sub.order_id;

-----внесување во табелата OrderPayment
INSERT INTO OrderPayment (employee_id, order_id, user_id, amount, payment_date, payment_method)
SELECT
    co.employee_id,
    co.order_id,
    co.user_id,
    co.total_price                              AS amount,   -- конзистентно со нарачката
    co.order_date + (random() * 3)::INT         AS payment_date,
    (ARRAY['Cash','Credit Card','Debit Card','Online','Voucher'])[1+(random()*4)::INT] AS payment_method
FROM CinemaOrder co;



UPDATE Reservation r
SET status = 'CONFIRMED'
WHERE EXISTS (
    SELECT 1 FROM Ticket t WHERE t.reservation_id = r.reservation_id
);

UPDATE Reservation r
SET status = (ARRAY['PENDING','CANCELLED']::statusReservation[])[1+(random()*1)::INT]
WHERE NOT EXISTS (
    SELECT 1 FROM Ticket t WHERE t.reservation_id = r.reservation_id
);
-----внесување во табелата PresentationRights
INSERT INTO PresentationRights (movie_id, cinema_id, start_date, end_date)
SELECT DISTINCT
    s.movie_id,
    h.cinema_id,
    DATE '2000-01-01',
    DATE '2030-12-31'
FROM Showtime s
JOIN Hall h ON h.hall_id = s.hall_id
ON CONFLICT DO NOTHING;

----------------------dopolnitelni filmovi za vo idnina dodadeni
INSERT INTO Showtime (movie_id, hall_id, start_time, end_time, base_price)
VALUES
-- CINEMA 1 (Hall 1-4)
(3,   1,  '2026-07-25 10:00:00', '2026-07-25 12:32:00', 450),  -- The Dark Knight
(8,   1,  '2026-07-25 18:00:00', '2026-07-25 20:28:00', 500),  -- Inception
(11,  2,  '2026-07-26 14:00:00', '2026-07-26 16:49:00', 420),  -- Interstellar
(26,  2,  '2026-07-26 20:00:00', '2026-07-26 22:12:00', 400),  -- Parasite
(52,  3,  '2026-07-27 10:00:00', '2026-07-27 11:47:00', 380),  -- Joker
(302, 3,  '2026-07-27 18:00:00', '2026-07-27 20:47:00', 480),  -- Dune Part Two
(9,   4,  '2026-07-28 12:00:00', '2026-07-28 14:16:00', 430),  -- The Matrix
(18,  4,  '2026-07-28 20:00:00', '2026-07-28 22:23:00', 460),  -- The Avengers
(27,  1,  '2026-07-29 16:00:00', '2026-07-29 18:05:00', 410),  -- Spirited Away
(71,  2,  '2026-07-29 20:00:00', '2026-07-29 21:40:00', 350),  -- Coco

-- CINEMA 2 (Hall 5-8)
(53,  5,  '2026-08-25 14:00:00', '2026-08-25 15:59:00', 400),  -- 1917
(54,  5,  '2026-08-25 20:00:00', '2026-08-25 21:46:00', 420),  -- Dunkirk
(19,  6,  '2026-08-26 10:00:00', '2026-08-26 12:42:00', 450),  -- Avatar
(55,  6,  '2026-08-26 18:00:00', '2026-08-26 19:56:00', 380),  -- Arrival
(68,  7,  '2026-08-27 14:00:00', '2026-08-27 16:14:00', 430),  -- Black Panther
(69,  7,  '2026-08-27 20:00:00', '2026-08-27 22:29:00', 500),  -- Avengers: Infinity War
(70,  8,  '2026-08-28 10:00:00', '2026-08-28 13:01:00', 520),  -- Avengers: Endgame
(22,  8,  '2026-08-28 18:00:00', '2026-08-28 19:47:00', 370),  -- Whiplash
(56,  5,  '2026-08-29 12:00:00', '2026-08-29 13:48:00', 390),  -- Ex Machina
(57,  6,  '2026-08-29 20:00:00', '2026-08-29 22:06:00', 410),  -- Her

-- CINEMA 3 (Hall 9-12)
(280, 9,  '2026-07-25 16:00:00', '2026-07-25 18:15:00', 440),  -- Oppenheimer
(281, 9,  '2026-07-26 20:00:00', '2026-07-26 21:54:00', 420),  -- Barbie
(282, 10, '2026-07-26 14:00:00', '2026-07-26 15:46:00', 390),  -- Past Lives
(283, 10, '2026-07-27 18:00:00', '2026-07-27 21:26:00', 480),  -- Killers of the Flower Moon
(285, 11, '2026-07-27 12:00:00', '2026-07-27 13:45:00', 400),  -- The Zone of Interest
(286, 11, '2026-07-28 20:00:00', '2026-07-28 22:21:00', 430),  -- Poor Things
(293, 12, '2026-07-28 14:00:00', '2026-07-28 16:28:00', 460),  -- Dune
(291, 12, '2026-07-29 10:00:00', '2026-07-29 12:38:00', 450),  -- Everything Everywhere All at Once
(292, 9,  '2026-07-29 18:00:00', '2026-07-29 19:54:00', 410),  -- The Banshees of Inisherin
(20,  10, '2026-07-30 20:00:00', '2026-07-30 22:19:00', 440);  -- Fight Club

------------------------Полнење на дополнително додадените филмови за во иднина
DO $$
DECLARE
    v_showtime    RECORD;
    v_seat        RECORD;
    v_reservation_id INT;
    v_seat_type_id   INT;
    v_base_price     INT;
    v_price          INT;
    v_user_id        INT;
    v_employee_id    INT;
    v_fill_count     INT;
    v_counter        INT;
BEGIN

    FOR v_showtime IN
        SELECT s.showtime_id, s.hall_id, s.base_price,
               h.cinema_id
        FROM Showtime s
        JOIN Hall h ON h.hall_id = s.hall_id
        ORDER BY s.showtime_id DESC
        LIMIT 30
    LOOP
        -- Случаен % пополнетост: 60–80% од 200 = 120–160 места
        v_fill_count := 120 + (random() * 40)::INT;
        v_counter    := 0;

        -- Земи вработен од истото кино
        SELECT employee_id INTO v_employee_id
        FROM Employee
        WHERE cinema_id = v_showtime.cinema_id
        ORDER BY random()
        LIMIT 1;

        FOR v_seat IN
            SELECT se.seat_id, se.seat_type_id
            FROM Seat se
            WHERE se.hall_id = v_showtime.hall_id
            ORDER BY random()
            LIMIT v_fill_count
        LOOP
            EXIT WHEN v_counter >= v_fill_count;

            -- Случаен корисник
            v_user_id := 1 + (random() * 99999)::INT;

            -- Пресметај цена според тип седиште
            v_price := (v_showtime.base_price * CASE v_seat.seat_type_id
                WHEN 1 THEN 1.0
                WHEN 2 THEN 2.0
                WHEN 3 THEN 1.5
                WHEN 4 THEN 1.8
                WHEN 5 THEN 0.7
                ELSE 1.0
            END)::INT;

            -- Резервација со статус CONFIRMED
            INSERT INTO Reservation (user_id, showtime_id, employee_id, reservation_date, status)
            VALUES (
                v_user_id,
                v_showtime.showtime_id,
                v_employee_id,
                CURRENT_DATE - (random() * 10)::INT,
                'CONFIRMED'
            )
            RETURNING reservation_id INTO v_reservation_id;

            -- Билет
            INSERT INTO Ticket (showtime_id, seat_id, reservation_id, price, purchase_date)
            VALUES (
                v_showtime.showtime_id,
                v_seat.seat_id,
                v_reservation_id,
                v_price,
                CURRENT_DATE - (random() * 10)::INT
            );

            -- Плаќање
            INSERT INTO ReservationPayment (
                user_id, reservation_id, employee_id,
                amount, payment_date, payment_method
            )
            VALUES (
                v_user_id,
                v_reservation_id,
                v_employee_id,
                v_price,
                CURRENT_DATE - (random() * 5)::INT,
                (ARRAY['Cash','Credit Card','Debit Card','Online','Voucher'])[1 + (random()*4)::INT]
            );

            v_counter := v_counter + 1;
        END LOOP;

        RAISE NOTICE 'Showtime %: % тикети внесени (сала %)',
            v_showtime.showtime_id, v_counter, v_showtime.hall_id;
    END LOOP;
END;
$$;



