---
#
#  Copyright 2020 Koha Development Team
#
#  This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <https://www.gnu.org/licenses>.

#
# *************************************************************
#      FASTADD KOHA MARC 21 BIBLIOGRAPHIC FRAMEWORK
# *************************************************************

description:
  - "'FA', a 'Fast Add' minimal MARC21 framework suitable for ILL or on-the-fly cataloguing."

tables:
  - biblio_framework:
      translatable: [ frameworktext ]
      multiline: []
      rows:
        - frameworkcode: FA
          frameworktext: "Fast Add Framework"

sql_statements:
  - "INSERT IGNORE INTO marc_tag_structure (tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value, frameworkcode)
    SELECT tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value, 'FA'
    FROM marc_tag_structure
    WHERE frameworkcode = '' AND
    tagfield IN ('000', '008', '010', '020', '022', '050', '082', '090', '099', '100', '245', '250', '260', '300', '500', '942', '952', '999');"

  - "INSERT IGNORE INTO marc_subfield_structure (tagfield, tagsubfield, liblibrarian, libopac, repeatable, mandatory, kohafield, tab, authorised_value, authtypecode, value_builder, isurl, hidden, frameworkcode, seealso, link, defaultvalue)
    SELECT tagfield, tagsubfield, liblibrarian, libopac, repeatable, mandatory, kohafield, tab, authorised_value, authtypecode, value_builder, isurl, hidden, 'FA', seealso, link, defaultvalue
    FROM marc_subfield_structure
    WHERE frameworkcode = '' AND
    tagfield IN ('000', '008', '010', '020', '022', '050', '082', '090', '099', '100', '245', '250', '260', '300', '500', '942', '952', '999');"

  # REVERT HIDDEN FIELD TO ORIGINAL (pre copy ) VALUES
  - "UPDATE marc_subfield_structure SET tab = 0 WHERE tagfield IN ('100','245','250','260','300','500','942') AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-5' WHERE tagfield = '010' AND tagsubfield = 'a' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-5' WHERE tagfield = '010' AND tagsubfield = 'b' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-5' WHERE tagfield = '010' AND tagsubfield = 'z' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '020' AND tagsubfield = 'c' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '020' AND tagsubfield = 'q' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-5' WHERE tagfield = '020' AND tagsubfield = 'z' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '022' AND tagsubfield = '2' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '022' AND tagsubfield = 'a' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-5' WHERE tagfield = '022' AND tagsubfield = 'y' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-5' WHERE tagfield = '022' AND tagsubfield = 'z' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '050' AND tagsubfield = 'a' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '050' AND tagsubfield = 'b' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '082' AND tagsubfield = '2' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '082' AND tagsubfield = 'a' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '082' AND tagsubfield = 'b' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '100' AND tagsubfield = 'd' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '100' AND tagsubfield = 'e' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '100' AND tagsubfield = 'q' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '245' AND tagsubfield = 'h' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '245' AND tagsubfield = 'n' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '245' AND tagsubfield = 'p' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '250' AND tagsubfield = 'a' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '250' AND tagsubfield = 'b' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '260' AND tagsubfield = 'a' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '260' AND tagsubfield = 'b' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '260' AND tagsubfield = 'c' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '300' AND tagsubfield = 'a' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '300' AND tagsubfield = 'a' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '300' AND tagsubfield = 'b' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '300' AND tagsubfield = 'c' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '300' AND tagsubfield = 'e' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '300' AND tagsubfield = 'f' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '300' AND tagsubfield = 'g' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '500' AND tagsubfield = 'a' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '942' AND tagsubfield = 'e' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '942' AND tagsubfield = 'h' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '942' AND tagsubfield = 'i' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '942' AND tagsubfield = 'k' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-1' WHERE tagfield = '942' AND tagsubfield = 'm' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = '0' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = '4' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = '5' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'e' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'f' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'g' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'i' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-5' WHERE tagfield = '952' AND tagsubfield = 'j' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 't' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'u' AND frameworkcode = 'FA';"
  - "UPDATE marc_subfield_structure SET hidden ='-6' WHERE tagfield = '952' AND tagsubfield = 'w' AND frameworkcode = 'FA';"
