/*
 * Copyright (c) All respective contributors to the Peridot Project. All rights reserved.
 * Copyright (c) 2021-2022 Rocky Enterprise Software Foundation, Inc. All rights reserved.
 * Copyright (c) 2021-2022 Ctrl IQ, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors
 * may be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

\set rl8Id '''35846917-973e-4e7a-b471-2fe407645601'''
\set supportedPackages8Id '''5ef98f35-421c-4b2d-9ae8-5d7ef4d5943b'''
\set rocky9Id '''c5de9987-6a11-447e-924b-68e23dcd1baa'''

\set bashId '''9fb2dcc3-c04f-4608-9060-e0bdcc406e14'''
\set opensslId '''ec985b13-2509-49da-bd57-b4ea8fb6c291'''
\set memcachedId '''8356140c-e8d9-4536-a99f-a2ea6c772794'''
\set httpdId '''22868644-6702-4a5e-bb6e-45a23adfcc13'''
\set mod_http2Id '''ff75e989-87c7-42e5-8f22-cf5c072e5c1f'''
\set mod_mdId '''4d391a68-33b9-4ade-a86e-d317132b8e54'''
\set nginxId '''60eb3a47-0547-42b9-87fc-0bec0696fb5f'''
\set redisId '''29e8c36d-18c3-4004-8623-e3d07534396c'''
\set aclId '''2618c69f-f8c2-4b74-9cb6-cfcea513c02f'''
\set utilLinuxId '''fb91fe60-7a12-490a-a143-8d1a0cd71b69'''
\set libexifId '''ae822eac-2aee-4f2f-b4c2-440f570d533e'''
\set libinputId '''3c8efb42-aacc-4110-bdbe-fa8a1be58b83'''
\set libpcapId '''45c67896-3fb7-4a5c-9e27-82407887ebf5'''
\set libpngId '''bc18261b-cf52-42da-8b9a-14a660e0c224'''
\set libtarId '''9cb79bd7-f86c-4f47-8ea4-b7e5af20b3c7'''
\set libtoolId '''e04716fb-ed0c-4dac-88fc-768777338d88'''
\set libX11Id '''da73ae49-60cf-4ff7-b8d1-7e03352d3e46'''
\set autoconfId '''9ff07714-438e-4497-a220-fb75b25bf627'''
\set libuserId '''088a1688-4a6e-4bd5-b7e2-9eb29da9114e'''
\set openldapId '''1d75baeb-6a02-40e7-9155-93bca5da2d64'''
\set libselinuxId '''ce5a9a03-4fc9-471d-857c-a4ce0468a1e4'''
\set libselinuxPythonId '''24959aff-1ecb-4f1c-ad46-b27e5f7b1d68'''

insert into projects (id, name, major_version, target_gitlab_host, target_prefix,
                      target_branch_prefix, source_git_host,
                      source_prefix, source_branch_prefix, dist_tag_override, branch_suffix, archs)
values (:rocky9Id, 'Rocky Linux 9', 9, 'https://gitlab.com',
        'rocky-9-test', 'r',
        'https://git.centos.org', '', 'c',
        'el9', '',
        array ['x86_64', 'aarch64']);

insert into projects (id, name, major_version, target_gitlab_host, target_prefix,
                      target_branch_prefix, source_git_host,
                      source_prefix, source_branch_prefix, cdn_url, dist_tag_override, archs)
values (:rl8Id, 'Rocky Linux 8', 8, 'https://gitlab.com',
        'rocky-8-test', 'r',
        'https://git.centos.org', '', 'c', 'https://rocky-linux-sources-staging.a1.rockylinux.org',
        'el8',
        array ['aarch64']);

-- the packages here are split into multiple queries
-- so they get a unique created_at value
insert into packages (id, name, package_type)
values (:bashId, 'bash', 2);
insert into packages (id, name, package_type)
values (:opensslId, 'openssl', 2);
insert into packages (id, name, package_type)
values (:memcachedId, 'memcached', 2);
insert into packages (id, name, package_type)
values (:httpdId, 'httpd', 10);
insert into packages (id, name, package_type)
values (:mod_http2Id, 'mod_http2', 7);
insert into packages (id, name, package_type)
values (:mod_mdId, 'mod_md', 7);
insert into packages (id, name, package_type)
values (:nginxId, 'nginx', 10);
insert into packages (id, name, package_type)
values (:redisId, 'redis', 10);
insert into packages (id, name, package_type)
values (:aclId, 'acl', 2);
insert into packages (id, name, package_type)
values (:utilLinuxId, 'util-linux', 2);
insert into packages (id, name, package_type)
values (:libexifId, 'libexif', 2);
insert into packages (id, name, package_type)
values (:libinputId, 'libinput', 2);
insert into packages (id, name, package_type)
values (:libpcapId, 'libpcap', 2);
insert into packages (id, name, package_type)
values (:libpngId, 'libpng', 2);
insert into packages (id, name, package_type)
values (:libtarId, 'libtar', 2);
insert into packages (id, name, package_type)
values (:libtoolId, 'libtool', 2);
insert into packages (id, name, package_type)
values (:libX11Id, 'libX11', 2);
insert into packages (id, name, package_type)
values (:autoconfId, 'autoconf', 2);
insert into packages (id, name, package_type)
values (:libuserId, 'libuser', 2);
insert into packages (id, name, package_type)
values (:openldapId, 'openldap', 2);
insert into packages (id, name, package_type)
values (:libselinuxId, 'libselinux', 9);
insert into packages (id, name, package_type)
values (:libselinuxPythonId, 'libselinux-python', 6);

insert into project_packages (project_id, package_id)
values (:rl8Id, :bashId),
       (:rl8Id, :opensslId),
       (:rl8Id, :memcachedId),
       (:rl8Id, :httpdId),
       (:rl8Id, :mod_http2Id),
       (:rl8Id, :mod_mdId),
       (:rl8Id, :nginxId),
       (:rl8Id, :redisId),
       (:rl8Id, :aclId),
       (:rl8Id, :utilLinuxId),
       (:rl8Id, :libexifId),
       (:rl8Id, :libinputId),
       (:rl8Id, :libpcapId),
       (:rl8Id, :libpngId),
       (:rl8Id, :libtarId),
       (:rl8Id, :libtoolId),
       (:rl8Id, :libX11Id),
       (:rl8Id, :autoconfId),
       (:rl8Id, :libuserId),
       (:rl8Id, :openldapId),
       (:rl8Id, :libselinuxId),
       (:rl8Id, :libselinuxPythonId);

insert into external_repositories (id, project_id, url)
values (gen_random_uuid(), :rl8Id,
        'https://dl.rockylinux.org/pub/rocky/8/BaseOS/$arch/os'),
       (gen_random_uuid(), :rl8Id,
        'https://dl.rockylinux.org/pub/rocky/8/AppStream/$arch/os'),
       (gen_random_uuid(), :rl8Id,
        'https://dl.rockylinux.org/pub/rocky/8/Devel/$arch/os'),
       (gen_random_uuid(), :rl8Id,
        'https://dl.rockylinux.org/pub/rocky/8/PowerTools/$arch/os');

insert into external_repositories (id, project_id, url)
values (gen_random_uuid(), :rocky9Id,
        'https://bootstrap9.releng.rockylinux.org/repos_stage1/9-lazystrap-$arch'),
       (gen_random_uuid(), :rocky9Id,
        'https://bootstrap9.releng.rockylinux.org/repos_stage1/9-lazystrap_noarch');

insert into project_repos (id, name, project_id, packages)
values ('ff6d97f2-3155-499c-af63-2a553f2abd6b', 'all', :rl8Id, array [] :: text[]),
       ('d6b5bfa1-51c1-4ea2-bda0-83dd71844b45', 'BaseOS', :rl8Id,
        array [
            'bash',
            'openssl',
            'acl',
            'util-linux',
            'libpcap',
            'libpng'
            ] :: text[]),
       ('07c3ca19-411f-40a0-bb6d-711419ccb8a2', 'AppStream', :rl8Id,
        array [
            'memcached',
            'module:httpd:2.4',
            'module:httpd-devel:2.4',
            'module:nginx:1.14',
            'module:nginx-devel:1.14',
            'module:nginx:1.16',
            'module:nginx-devel:1.16',
            'module:nginx:1.18',
            'module:nginx-devel:1.18',
            'module:nginx-devel:1.18',
            'module:nginx:1.20',
            'module:nginx-devel:1.20',
            'module:redis:5',
            'module:redis-devel:5',
            'module:redis:6',
            'module:redis-devel:6',
            'module:libselinux-python:2.8',
            'module:libselinux-python-devel:2.8',
            'libexif',
            'libinput',
            'libtar',
            'libtool',
            'libX11',
            'autoconf'
            ] :: text[]);

insert into project_module_configuration (id, project_id, proto, active)
values ('063cc50b-1216-4a6b-8095-ce9583d512fc', :rl8Id, '{
  "@type": "type.googleapis.com/resf.peridot.v1.ModuleConfiguration",
  "platform": {
    "major": 8,
    "minor": 5,
    "patch": 0,
    "provides": [
      "el8",
      "el8.5.0"
    ],
    "buildroot": {
      "rpm": [
        "rocky-release"
      ]
    },
    "srpmroot": {
      "rpm": [
        "rocky-release"
      ]
    }
  },
  "default": [
    {
      "name": "nginx",
      "stream": "1.14",
      "common_profile": [
        "1.14",
        "1.16",
        "1.18",
        "1.20"
      ]
    },
    {
      "name": "httpd",
      "stream": "2.4",
      "common_profile": [
        "2.4"
      ]
    },
    {
      "name": "redis",
      "stream": "5",
      "common_profile": [
        "5",
        "6"
      ]
    }
  ]
}'::jsonb, true);
