// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

///|
/// Backward-compatibility `Show` impls after `derive(Show)` deprecation.
///
/// We keep source-level derives on `Debug` and manually expose `Show` for API and tests.

///|
fn[T : @debug.Debug] show_from_debug(value : T, logger : &Logger) -> Unit {
  let rendered = @debug.render(@debug.Debug::to_repr(value))
  logger.write_string(
    rendered.replace_all(old="{ ", new="{").replace_all(old=" }", new="}"),
  )
}

///|
pub impl Show for NativeOs with fn output(self : NativeOs, logger : &Logger) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for I24 with fn output(self : I24, logger : &Logger) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for U24 with fn output(self : U24, logger : &Logger) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for Duration with fn output(self : Duration, logger : &Logger) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for StreamInstant with fn output(
  self : StreamInstant,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for InputStreamTimestamp with fn output(
  self : InputStreamTimestamp,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for OutputStreamTimestamp with fn output(
  self : OutputStreamTimestamp,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for InputCallbackInfo with fn output(
  self : InputCallbackInfo,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for OutputCallbackInfo with fn output(
  self : OutputCallbackInfo,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for DeviceType with fn output(self : DeviceType, logger : &Logger) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for InterfaceType with fn output(
  self : InterfaceType,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for DeviceDirection with fn output(
  self : DeviceDirection,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for DeviceDescription with fn output(
  self : DeviceDescription,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for DeviceDescriptionBuilder with fn output(
  self : DeviceDescriptionBuilder,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for BackendSpecificError with fn output(
  self : BackendSpecificError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for DefaultStreamConfigError with fn output(
  self : DefaultStreamConfigError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for SupportedStreamConfigsError with fn output(
  self : SupportedStreamConfigsError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for DevicesError with fn output(
  self : DevicesError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for DeviceNameError with fn output(
  self : DeviceNameError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for BuildStreamError with fn output(
  self : BuildStreamError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for PlayStreamError with fn output(
  self : PlayStreamError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for PauseStreamError with fn output(
  self : PauseStreamError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for StreamError with fn output(
  self : StreamError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for Data with fn output(self : Data, logger : &Logger) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for DeviceIdError with fn output(
  self : DeviceIdError,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for DeviceId with fn output(self : DeviceId, logger : &Logger) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for HostUnavailable with fn output(
  self : HostUnavailable,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for HostId with fn output(self : HostId, logger : &Logger) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for BufferSize with fn output(self : BufferSize, logger : &Logger) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for StreamConfig with fn output(
  self : StreamConfig,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for SupportedBufferSize with fn output(
  self : SupportedBufferSize,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for SampleFormat with fn output(
  self : SampleFormat,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for SupportedStreamConfig with fn output(
  self : SupportedStreamConfig,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}

///|
pub impl Show for SupportedStreamConfigRange with fn output(
  self : SupportedStreamConfigRange,
  logger : &Logger,
) -> Unit {
  show_from_debug(self, logger)
}