module infix-system {
  yang-version 1.1;
  namespace "urn:infix:system:ns:yang:1.0";
  prefix infix-sys;

  import ietf-system {
    prefix sys;
  }
  import iana-timezones {
    prefix iana-tz;
  }
  import infix-shell-type {
    prefix infixsh;
  }

  include infix-system-software;

  organization "KernelKit";
  contact      "kernelkit@googlegroups.com";
  description  "Infix augments and deviations to ietf-system.";

  revision 2024-02-29 {
    description "Mark infix-sys:motd as deprecated, to be replaced with type binary.";
    reference "internal";
  }

  revision 2023-10-19 {
    description "Change deviation for timezone-utc-offset from unsupported to Etc+/-HOUR
                - Unit is set to hours (tzdata compatibility)
                - Range is -12 .. 14";

    reference "internal";
  }

  revision 2023-08-15 {
    description "Add support for user login shell.

                 Update/add deviation specifications:
                  - timezone-name (use tz defs from iana-timezone.yang)
                  - timezone-utc-offset (updated path for 'not-supported')
                  - radius ('not-supported')
                  - dns-resolver port ('not-supported')
                  - authentication username (limit length and pattern)";
    reference "internal";
  }

  revision 2023-04-11 {
    description "Initial revision.";
    reference "internal";
  }

  /*
   * Identities
   */

  identity editor-type {
    description "Base identity from which specific editor types are derived.";
  }

  identity emacs {
    description "Micro Emacs clone (mg).";
    base editor-type;
  }
  identity nano {
    description "GNU Nano.";
    base editor-type;
  }
  identity vi {
    description "The classic UNIX Visual editor.";
    base editor-type;
  }

  /*
   * Typedefs
   */

  typedef username {
    type string {
      length "1..256";
      pattern "[_a-zA-Z0-9][-._a-zA-Z0-9]*$?";
    }
  }

  /*
   * Data nodes
   */

  augment "/sys:system" {
    description "Augment of ietf-system for modifying /etc/motd.";

    leaf motd {
      description "Legacy MotD (Message of the Day), shown after login.

                   Please note, this is obsolete!  When set it overrides the
                   'motd-banner' setting for backwards compatibility.

                   Instead, use 'motd-banner', which takes a base64 encoded
                   text file as an argument.  For CLI users, edit with the
                   'text-editor motd-banner' command.";
      status obsolete;      // Replaced with motd-banner (binary)
      type string;
    }

    // From openconfig-system, which also has login-banner (TODO)
    leaf motd-banner {
      description "Message of the Day (MotD), shown after SSH/console login.

                   Base64 encoded (binary) file contents for the system file
                   /etc/motd, displayed after SSH/console login.

                   They system may append additional standard information such
                   as the current system date and time, uptime, last login
                   timestamp, etc.";
      type binary;
    }

    leaf text-editor {
      description "Text editor to use in CLI for text-editor command.";
      type identityref {
        base editor-type;
      }
      default emacs;
    }
  }

  augment "/sys:system/sys:authentication/sys:user" {
    description "Augment of ietf-system to support setting login shell for users.";
    leaf shell {
      type identityref {
        base infixsh:shell-type;
      }
      default infixsh:false;
      description "Set UNIX login shell for user, default: none (security)";
    }
  }

  deviation "/sys:system/sys:clock/sys:timezone/sys:timezone-name/sys:timezone-name" {
    deviate replace {
      type iana-tz:iana-timezone;
    }
  }

  deviation "/sys:system/sys:clock/sys:timezone/sys:timezone-utc-offset/sys:timezone-utc-offset" {
    description "Timezone UTC offset should be set in hours, not minutes";
    deviate replace {
      type int16 {
        range "-12 .. 14";
      }
      units "hours";
    }
  }

  deviation "/sys:system/sys:radius" {
    deviate not-supported;
  }

  deviation "/sys:system/sys:dns-resolver/sys:server/sys:transport/sys:udp-and-tcp/sys:udp-and-tcp/sys:port" {
    deviate not-supported;
  }

  deviation "/sys:system/sys:authentication/sys:user/sys:name" {
    deviate replace {
      type infix-sys:username;
    }
  }
}
