/// Build an error message prefixed by a module or mixin name.
///
/// @group schema
///
/// @parameter {String} $module  - module name
/// @parameter {String} $message - error message
///
/// @return {String}
///
/// @example scss - Usage
///   k-module-error('module', 'something went wrong');
///   // Will return '[module]: something went wrong'
@function k-module-error($module, $message) {
  @return "[#{$module}]: #{$message}";
}

/// Raise an error message for a specific module and path.
///
/// @group schema
///
/// @parameter {String} $module  - module name
/// @parameter {String} $path    - path to invalid attribute
/// @parameter {String} $message - error message
///
/// @example scss - Usage
///   k-schema-error('module', 'margin.top', 'is not a number');
///   // Will throw '[module]: margin.top is not a number'
@function k-schema-error($module, $path, $message) {
  $error-message: k-module-error(
    $module,
    "#{$path} #{$message}"
  );

  $error-message: k-log($error-message);
}

/// Raise a invalid unit error for a specific module and path.
///
/// @group schema
///
/// @parameter {String} $module    - module name
/// @parameter {String} $path      - path to invalid attribute
/// @parameter {String|List} $unit - expected unit
///
/// @example scss - Usage
///   k-unit-error('module', 'margin.top', (px, rem));
///   // Will throw '[module]: margin.top should be one of px, rem'
@function k-unit-error($module, $path, $unit) {
  @if type-of($unit) == 'string' {
    @if $unit == none {
      @return k-schema-error(
        $module, $path,
        'should be a unitless number'
      );
    }
    @else {
      @return k-schema-error(
        $module, $path,
        "should be defined in #{$unit}"
      );
    }
  }
  @elseif type-of($unit) == 'list' {
    @return k-schema-error(
      $module, $path,
      "should be one of #{$unit}"
    );
  }
}
