package action

import (
	. "ios-wrapper/internal/wrapper/ofile"
)

// Actions on MachoFile
type Action interface {
	withMacho(mf *MachoFile) error
	withFat(ff *FatFile) error
	// TODO: error context
}

func RunAction(action Action, ofile OFile) error {
	switch ofile.(type) {
	case *MachoFile:
		return action.withMacho(ofile.(*MachoFile))
	case *FatFile:
		return action.withFat(ofile.(*FatFile))
	}
	// not likely
	return nil
}

func defaultWithFat(action Action, ff *FatFile) error {
	for _, macho := range ff.Machos() {
		err := action.withMacho(macho)
		if err != nil {
			return err
		}
	}
	return nil
}